Depth - First - Traversal Exam Questions 2
Depth - First - Traversal Exam Questions 2
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
State why the tree shown in Fig. 1 is not an example of a binary search tree.
[1]
(b). Kira wants the program to traverse the tree to evaluate the range of possible moves. She is considering
using a breadth-first traversal or a depth-first (post-order) traversal.
Show how a breadth-first traversal would traverse the tree shown in Fig. 1.
(c). Kira wants to make some changes to the data that is stored in the tree structure shown in Fig. 1.
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]
(d). Kira could have used a graph data structure to represent the moves in her game.
Give two similarities and two differences between a tree and a graph data structure.
Similarity 1
Similarity 2
Difference 2
[4]
(e). 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]
(f). State what is meant by the term ‘abstraction’ and describe how Kira has used abstraction in her design of
the tree.
[3]
Complete the diagram to show the contents of the tree after the following data is added: