Question

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
Official answer and solution
Official answer
B
From
Official GATE 2011 answer key

Solution

Use the property that the inorder traversal of any Binary Search Tree produces a uniquely sorted sequence.

  1. Let S={x1,x2,…,xn}S = \{x_1, x_2, \dots, x_n\} be a set of nn distinct keys sorted in strictly increasing order x1<x2<⋯<xnx_1 < x_2 < \dots < x_n.
  1. In any valid Binary Search Tree (BST), an inorder traversal visits all nodes in strictly increasing order of their key values.
  1. For a given, fixed unlabeled binary tree structure with nn nodes, the inorder traversal sequence of tree nodes is fixed and unique.
  1. Therefore, the kk-th node visited during the inorder traversal must receive the kk-th sorted element xkx_k for every k∈{1,2,…,n}k \in \{1, 2, \dots, n\}. There is exactly 1 unique valid assignment.
Final answer

B

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

Source

Paper
GATE 2011 Computer Science and Information Technology (CS)
Question
29 of 65, printed as CS Q.29
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.