The binary search tree shown was built by inserting the values 50, 30, 70, 20, 40, 60, 80 and 35 in that order.
(a) Write down the sequence of values produced by an in-order, a pre-order and a post-order traversal. [3]
(b) State the number of nodes examined (including the node holding 35) when searching for the value 35, starting at the root. [1]
(c) State which of the three traversals visits the values in ascending order. [1]
- (a) In-order: 20, 30, 35, 40, 50, 60, 70, 80(1)
- Pre-order: 50, 30, 20, 40, 35, 70, 60, 80(1)
- Post-order: 20, 35, 40, 30, 60, 80, 70, 50(1)
- (b) 4 nodes examined (50, 30, 40, 35)(1)
- (c) In-order traversal(1)
- Answer: (a) In: 20 30 35 40 50 60 70 80; Pre: 50 30 20 40 35 70 60 80; Post: 20 35 40 30 60 80 70 50 (b) 4 (c) in-order
- Examiner tip: Pre-order visits the node first, post-order last; write the node's position relative to its subtrees before listing.