Data Structures HW
Data Structures HW
The action the algorithm takes depends on the value input by the user. These actions are listed in Fig.
2.
Fig. 2
A stack is one data structure that is available for Sundip to use. She could also use a queue, list,
linked list, array or tuple.
[2]
[1]
(iv) Describe how the second item in a linked list would be accessed using pointer values.
[3]
(b)
(i) Complete the diagram to show the state of the stack after each value is entered into the algorithm.
The letters will complete an action stated in Fig. 2.
The state of the stack after the first value, 8, has been completed for you.
(ii) Complete the following table to give the output from this algorithm when the following set of inputs
are entered by the user. The letters will complete an action stated in Fig. 2.
9 3 A E
10 5 A 8 S E
25 5 S 2 3 A S E
[3]
(iii) If the user enters 4 2 S A E , the algorithm will not work correctly.
Explain what problem this input data will cause and why the problem occurs.
[3]
[4]
[1]
(ii) The figure below shows a queue data structure that contains a list of names. Alex is at the front of
the queue.
• enqueue() – This will add data that is passed in as a parameter to the queue.
• dequeue() – This will return the first element in the queue.
Show the contents of the queue after these operations have been performed:
enqueue("Charlie")
dequeue()
enqueue("Ling")
dequeue()
enqueue("Sara")
[2]
Fig. 5
[1]
(b)
[1]
(ii) State one way a graph data structure is different to a tree data structure.
[1]
State why the integer values are stored in an array instead of separate variables.
[1]
6(a) Kira is creating a computer game where the user can play against the computer.
In each turn, each character can make one move from a selection of possible moves.
Kira uses a tree data structure shown in Fig. 1 to identify the range of possible moves the computer
can make from starting position A. Each connection is a move, with each node representing the result
of the move.
Fig. 1
Kira could have used a graph data structure to represent the moves in her game.
Similarity 2
Difference 1
Difference 2
[4]
Describe the steps an algorithm will follow to delete node ‘E’ from the tree.
[3]
(ii) The move represented by the node ‘K’ needs to be added. Node ‘K’ needs to be joined to node ‘G.’
Describe the steps the algorithm will follow to add node ‘K’ to the right of node ‘G’.
[3]
Show how a breadth-first traversal would traverse the tree shown in Fig. 1.
[4]
(d) State what type of pointers are used to store nodes I, F, J and H so they do not point to any other
nodes.
[1]
(e) State why the tree shown in Fig. 1 is not an example of a binary search tree.
[1]