A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the…

2008

A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.

I. 81, 537, 102, 439, 285, 376, 305

II. 52, 97, 121, 195, 242, 381, 472

III. 142, 248, 520, 386, 345, 270, 307

IV. 550, 149, 507, 395, 463, 402, 270

Which of the following statements is TRUE?

  1. A.

    I, II and IV are inorder sequences of three different BSTs

  2. B.

    I is a preorder sequence of some BST with 439 as the root

  3. C.

    II is an inorder sequence of some BST where 121 is the root and 52 is a leaf

  4. D.

    IV is a postorder sequence of some BST with 149 as the root

Attempted by 159 students.

Show answer & explanation

Correct answer: C

Correct conclusion: Sequence II is an inorder traversal of a BST with 121 as root and 52 a leaf; the other statements are false.

Key facts used:

  • Inorder traversal of a BST lists values in strictly increasing (sorted) order.

  • Preorder traversal lists the root first.

  • Postorder traversal lists the root last.

Check each sequence:

  • Sequence I: 81, 537, 102, 439, 285, 376, 305 — not sorted ascending, so it cannot be an inorder traversal. It is, however, a valid preorder traversal of some BST (the first element 81 would be the root in that preorder).

  • Sequence II: 52, 97, 121, 195, 242, 381, 472 — sorted ascending, so it can be an inorder traversal. If 121 is chosen as the root, elements to its left (52, 97) form the left subtree and those to its right form the right subtree. A valid left-subtree arrangement is root 97 with left child 52, which makes 52 a leaf, so the stated configuration is possible.

  • Sequence IV: 550, 149, 507, 395, 463, 402, 270 — not sorted, so not inorder. For postorder the root must be last, but the last element here is 270, so 149 cannot be the root in a postorder traversal of a BST represented by this sequence.

Conclusion: The only statement that can be true as written is the one about Sequence II being an inorder traversal with 121 as root and 52 as a leaf.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir