Open In App

Data Structures | Binary Search Trees | Question 3

Like Article
Like
Save
Share
Report

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? (GATE CS 2011)

(A)

0

(B)

1

(C)

n!

(D)

(1/(n+1)).2nCn



Answer: (D)

Explanation:

There is only one way. The minimum value has to go to the leftmost node and the maximum value to the rightmost node. Recursively, we can define for other nodes.

Additionally, the number of distinct binary search trees possible for n nodes is similar to counting the number of distinct binary trees possible for n nodes assuming nodes are unlabeled. Hence, this value will also be 2nCn/(n+1).


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 06 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads