F453 - data structures and manipulation Flashcards

1
Q

Showing the steps of serial search
e.g. Find York
Aberdeen, Belfast, Cardiff, Oxford, York

A
  1. start at ‘Aberdeen’…
  2. look at each word in turn/then ‘Belfast’, ‘Cardiff’ etc…
  3. …until ‘York’ is found
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Showing the steps of binary search e.g. Find York

Aberdeen,Belfast, Cardiff, Oxford, York

A

look at middle/‘Cardiff’/‘Glasgow’
‘York’ is in second half of list
repeated halving…
…until ‘York’ is found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the advantages of binary search over seial search?

A

(usually) faster because…

…alf of data is discarded at each step/fewer item

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you add a data item into a stack?

A

if stack is full…
…report error and stop
increment pointer
add data item at position ‘pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can quicksort be used to put a set of numbers in ascending order?
e.g. 30 9 46 14 22

A

highlight first number in the list (the ‘search number’)
pointer at each end of list
repeat:
compare numbers being pointed to…
…f in wrong order, swap
move pointer of non-search number
until pointers coincide so search number in correct position
split list into 2 sublists
quick sort each sublist
repeat until all sublists have a single number
put sublists back together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name another method or sorting

A

insertion sort or bubble sort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a static data structure?

A

size is fixed when structure is created/size cannot change

during processing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What would be an advantage of static data structures over dynamic structures?

A

amount of storage is known/easier to program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you merge two files?
e.g. File A: Anna, Cleo,Helen, Pretti
FiLe B: Billy, Ian, Omar, Rob, Tom

A

(Anna, Billy, Cleo, Helen, Ian, Omar, Pritti, Rob, Tom)

You must: get correct order, use all names used once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

State the algorithm for merging two sorted files

A
open existing files
create new file
check existing files are not empty
use pointers/counters to identify records for
comparison
repeat
compare records indicated by pointers
copy earlier value record to new file
move correct pointer
until end of one file
copy remaining records from other file
close files
assume common key
assume if 2 records are the same…
…only 1 is written to new file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a dynamic data structure?

A

size changes as data is added & removed/size is not fixed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What would be a disadvantage to the programer of using dynamic data structures
over static ones?

A

more complex program to write

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

State a data structure which must be static

A

array/fixed length record

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What steps need to be taken to add a new item to a binary tree

A
start at root
repeat
compare new data with current data
if new data < current data, follow left pointer
else follow right pointer
until pointer is null
write new data
create (null) pointers for new data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can insertion sort be used to arrange numbers in order?

e.g. 17 2 3 26 5

A

list of sorted numbers is built up…

…with one number at a time being inserted into correct position

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

a list of positive numbers up to and including 1000 is

2,4,6,…500,502,…998,1000

an attempt is made to find 607

show the first 3 steps for a binary search

A

go to middle value 500
compare 607 with 500
607 > 500 therefore discard everything before 500 (including 500)
repeat process in remaining set of numbers (go to middle value etc)

17
Q

a list of positive numbers up to and including 1000 is

2,4,6,…500,502,…998,1000

an attempt is made to find 607

show the first 3 steps for a serial search

A

start at 2
compare 607 with 2 (no match)
compare 607 with 4 (no match)
& repeat comparison until match is found

18
Q

explain different between binary and serial search

A

binary search discards half of data at each step

serial search discards one data at each step

19
Q

one advantage of binary search
one disadvantage of binary search
compared with serial

A

binary usually faster in a large set of data because there are less comparisons to do
However disadvantage is that values must first be sorted in order but with serial it doesn’t need to be in order