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?
View worked solution
Answer: A
The correct option is A.
A fundamental property of any Binary Search Tree (BST) is that its inorder traversal always visits the nodes in sorted (ascending) order.
Since is a set of distinct integers, sorting the elements of in ascending order uniquely determines the inorder traversal of , regardless of the order in which the elements were inserted to construct the tree.
Why other options are incorrect:
The root node, preorder traversal, and postorder traversal depend entirely on the shape of the tree, which in turn depends on the insertion sequence of the elements. Since the insertion sequence is unknown, these cannot be uniquely determined.
Example:
Let .
- Case 1: If the insertion sequence is :
- The root is .
- Preorder traversal:
- Postorder traversal:
- Inorder traversal:
- Case 2: If the insertion sequence is :
- The root is .
- Preorder traversal:
- Postorder traversal:
- Inorder traversal:
As shown, while the root, preorder, and postorder traversals change based on the insertion sequence, the inorder traversal remains uniquely in all cases.
Free practice · Your answers on this page are not saved.
