Question
Which of the following is/are correct inorder traversal sequence(s) of binary search tree(s)?
I.
II.
III.
IV.
Official answer and solution
- Official answer
- A
- From
- Official GATE 2015 answer key
Solution
Recall that the inorder traversal of any Binary Search Tree produces a monotonically non-decreasing (strictly increasing for distinct keys) sequence.
In a Binary Search Tree (BST), the left subtree contains keys smaller than the root, and the right subtree contains keys greater than the root.
An inorder traversal visits , which always outputs keys in strictly ascending sorted order.
Testing each sequence:
- I: (Strictly increasing: Valid)
- II: (Contains , not sorted: Invalid)
- III: (Contains , not sorted: Invalid)
- IV: (Strictly increasing: Valid)
Therefore, only I and IV are correct inorder traversal sequences of binary search trees (option A).
A
Confusing inorder traversal with preorder or postorder traversal, where keys do not appear in sorted order.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 1
- Question
- 20 of 65, printed as CS Q.10
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.