Skip to content
Official PYQ · 2011

GATE CS 2011 Q29 — Trees

Explain with AI

We are given a set of nn distinct elements and an unlabeled binary tree with nn nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?

Choose one option
View worked solution

Answer: B

To form a Binary Search Tree (BST) from a given set of nn 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 nn nodes:

  1. The in-order traversal visits the nn nodes in a unique, fixed sequence of positions.
  2. Since the nn elements are distinct, there is exactly one unique sorted arrangement of these elements.

To satisfy the BST property, we must assign the ii-th smallest element of our sorted set to the ii-th node visited during the in-order traversal of the tree, for all 1≤i≤n1 \le i \le n.

Since both the sorted sequence of elements and the in-order traversal path of the tree structure are unique, there is exactly 11 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.

Published
Report a correction
Keep exploringMore Trees questions