You are given a set 𝑉 of distinct integers. A binary search tree 𝑇 is…

2024

You are given a set 𝑉 of distinct integers. A binary search tree 𝑇 is created by inserting all elements of 𝑉 one by one, starting with an empty tree. The tree 𝑇 follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in which these values were inserted into 𝑇, and you do not have access to 𝑇.

Which one of the following statements is TRUE?

  1. A.

    Inorder traversal of 𝑇 can be determined from 𝑉

  2. B.

    Root node of 𝑇 can be determined from 𝑉

  3. C.

    Preorder traversal of 𝑇 can be determined from 𝑉

  4. D.

    Postorder traversal of 𝑇 can be determined from 𝑉

Attempted by 342 students.

Show answer & explanation

Correct answer: A

Key insight: inorder traversal of a binary search tree visits nodes in increasing order.

Reason:

  • Because every node's left subtree contains only smaller values and the right subtree only larger values, the inorder procedure (left, node, right) produces the elements in sorted (ascending) order.

  • Given the set V of distinct integers, sorting V gives the inorder traversal of T. This is independent of the insertion order.

  • Preorder, postorder and the choice of root depend on the insertion order (they depend on the tree shape), so they cannot be determined from V alone.

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

Explore the full course: Gate Guidance By Sanchit Sir