We are given a set of distinct elements and an unlabeled binary tree with nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
View worked solution
Answer: B
To form a Binary Search Tree (BST) from a given set of distinct elements, the elements must satisfy the BST property. Specifically, the in-order traversal of any BST must produce the elements in a strictly sorted (ascending) order.
For any fixed, unlabeled binary tree structure with nodes:
- The in-order traversal visits the nodes in a unique, fixed sequence of positions.
- Since the elements are distinct, there is exactly one unique sorted arrangement of these elements.
To satisfy the BST property, we must assign the -th smallest element of our sorted set to the -th node visited during the in-order traversal of the tree, for all .
Since both the sorted sequence of elements and the in-order traversal path of the tree structure are unique, there is exactly way to populate the given tree structure to make it a BST.
Therefore, the correct option is B.
Free practice · Your answers on this page are not saved.
