Exam-style question
Try this first
The values in the following binary search tree are arranged so that an in-order traversal should produce them in ascending order. Which sequence is produced by an in-order traversal of this tree: root 50, left child 30, right child 70, 30's children 20 and 40, and 70's children 60 and 80?.
- A.50, 30, 20, 40, 70, 60, 80
- B.20, 30, 40, 50, 60, 70, 80
- C.20, 40, 30, 60, 80, 70, 50
- D.80, 70, 60, 50, 40, 30, 20
Model answer
What a good answer should say
- 20, 30, 40, 50, 60, 70, 80
Explanation
Why this works
In-order visits the left subtree, then the current node, then the right subtree. For a binary search tree, this outputs the contents in ascending order.
Common mistake
No common mistake is linked to this question yet.
