Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

ALGORITHM DESIGN AND DATA STRUCTURES

REVISION EXERCISE

Questions
1. (a) State the difference between dynamic and static data structures
giving an example of each. (3)

b) Show how a binary tree can be used to store the data items Feddi,
Eda, Joh, Sean, Dav, Gali in alphabetic order. (4)

c) Explain why problems may arise if Joh is deleted from the tree and
how such problems may be overcome.

2. An array is to be used to store information. State three parameters


that need to be given about the array before it can be used, explaining
the reason why each is necessary.

3. (a) Explain the difference between static and dynamic data structures.
[2]
(b) Give an example of a
(i) static,
(ii) dynamic
data structure, giving an advantage of each. [4]
(c) The details of a car part are stored in a binary tree according to this
algorithm
READ VALUE NEW_PART
START AT ROOT NODE
WHILE NODE NOT EMPTY, DO
IF NEW_PART < VALUE AT NODE
THEN FOLLOW LEFT SUBTREE
ELSE FOLLOW RIGHT SUBTREE
ENDIF
ENDWHILE
INSERT NEW_PART AT NODE
END
(i) Show the binary tree after the following values have been input
Radio Visor Brakes Tyres Alternator Windscreen [3]
(ii) Explain how Clutch is added to the tree in (i). [5]
(iii) Describe an algorithm that can be applied to the binary tree of car
parts, so that the tree is read in
alphabetic order.
4
The following binary tree diagram contains a number of integers. In each
case the right pointer
indicates the condition “higher number” and the left pointer indicates
the condition “lower or equal
number”.

i) Write down the integer contained in the root node. [1]


(ii) Write down the order in which the nodes would be accessed to find
the integer 2528. [1]
(iii) Copy the tree and show where a new node containing the integer
3106 would be added. [1]
(iv) The integer 2550 is not in the diagram. Explain what would happen if
a search was made for this
code.
5. An array x[1..n] contains a number of integer values.
Design an algorithm (in pseudo-code or a high- level programming
language) which will carry out a
linear search of the array for a given search element. If the element is
found, it should output the
position of the search element. If the element is not found, the
algorithm should output zero.
6. Convert the following expressions from infix to postfix (Reverse
Polish) notation.
a) 5 * 6
b) (5 * 4) – 3
c) (6 * 3) / (2 + 4)
7.Convert the following expressions from postfix to infix.
a) 12 4 / 2 +
b) 4 4 * 2 2 * +
c) 24 6 / 3 2 + 2 /
8.Draw a binary tree for the expression (5 + 6) * 3.
9. What would be the result of the following traversals on the tree you
made for question 3?
a) in-order
b) post-order
c) pre-order
10. What is the purpose of Reverse Polish Notation?
11.Explain why infifix notation is used by humans whereas postfifix
notation
may be used by an interpreter or compiler.
12. Explain how you could use a bubble sort and a merge sort to sort the
following list of data:
12, 3, 4, 8, 2, 6, 10, 5
13. Explain why a bubble sort requires data to be stored in an array.
14. Would a bubble sort or merge sort be the quickest way of sorting
this list? Explain your answer.
16. What if there were one million items in a list? Which would be the
quickest then? Explain you answer.
17.Bubble sort uses ‘iteration’ and a merge sort uses ‘recursion’. What
do these terms mean and why are they needed?

You might also like