We are given a set of n distinct elements and an unlabelled binary tree with n…
2025
We are given a set of n distinct elements and an unlabelled binary tree with n nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
- A.
0
- B.
1
- C.
n!
- D.
(1/(n+1)).2nCn
Attempted by 177 students.
Show answer & explanation
Correct answer: B
The number of ways to populate an unlabelled binary tree with n distinct elements to form a binary search tree depends on the structure of the tree. For a given tree structure, the BST property requires that for each node, all values in the left subtree are less than the node's value, and all values in the right subtree are greater. This constraint restricts the valid assignments. The number of valid labelings is equal to the number of ways to assign the n distinct values such that the BST ordering is preserved. For a fixed tree shape, this number is 1 if the structure is a valid BST shape, but in general, it is determined by the number of valid inorder traversals that respect the tree's structure. The correct count is not simply n! or the Catalan number, but depends on the specific tree structure.