Question

You are given a set VV of distinct integers. A binary search tree TT is created by inserting all elements of VV one by one, starting with an empty tree. The tree TT 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 TT, and you do not have access to TT.

Which one of the following statements is TRUE?

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2024 answer key

Solution

Use the fundamental property that the inorder traversal of any BST on a set VV of keys is always the keys of VV in sorted ascending order.

Regardless of the insertion sequence or the resulting shape of the Binary Search Tree TT, an inorder traversal (Left -> Node -> Right) of a BST always visits the keys in strictly increasing sorted order. Since the set VV of keys is known, sorting VV uniquely determines the inorder traversal of TT. By contrast, the root node, preorder traversal, and postorder traversal all depend on the order in which elements of VV were inserted.

Final answer

Option (A)

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2024 Computer Science and Information Technology - Set 2 (CS2)
Question
39 of 65
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.