GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 33

Inorder traversal of a binary search tree

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2005 paper

GATE 2005, Q33 2 marks · MCQ
Report issue

Binary Search & Balanced Trees

Question 33, GATE 2005: BST postorder is 10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29. Candidate inorder A9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95; B9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29; C29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95; D95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Inorder traversal of a BST with distinct keys lists them in increasing order. Sorting the displayed key set gives 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95, option A. No full reconstruction from postorder is necessary.

For distinct keys in a BST, inorder visits every smaller key before the root and every larger key afterward, recursively producing the sorted key list. Sorting the supplied set gives A. There is no need to reconstruct the full shape from postorder unless the task asks for structure; postorder here merely specifies which keys are present.

Original paper, page 4