recategorized by
32,577 views
48 votes
48 votes

We are given a set of $n$ distinct elements and an unlabeled 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?

  1. $0$
  2. $1$
  3. $n!$
  4. $\frac{1} {n+1} .^{2n}C_n$
recategorized by

9 Answers

Best answer
88 votes
88 votes

With $n$ nodes, there are $\frac{^{2n}Cn}{(n+1)}$ distinct tree structures possible.

Corresponding to each structure, only one binary search tree (BST) can be formed because inorder is fixed.

Here, we are already given one such structure therefore only one tree possible.

If binary trees would have been asked, $n!$ trees would have been possible corresponding to each distinct tree structure. Here, tree structure is fixed and hence, we can have only one possibility for BST as elements are distinct. For general cases:
http://gatecse.in/wiki/Number_of_Binary_trees_possible_with_n_nodes 

 

Correct Answer: $B$

edited by
32 votes
32 votes
Given binary tree is unlabeled . So as it is given we are not allowed to change the formation of tree. Then To make it BST we can use atmost 1 way . As for particular structure we can not use n! arrangement of nodes (Becasue they are labeled and it is BST not BT)
22 votes
22 votes

READ QUESTION VERY CAREFULLY

 

10 votes
10 votes

With n nodes there are 2nCn/(n+1) different structure. One structure out of these 2nCn/(n+1) structures is given.

Now no of ways to fill numbers in given structure to ensure BST property is one and only one.

http://gatecse.in/wiki/Number_of_Binary_trees_possible_with_n_distinct_nodes

Answer:

Related questions

12.0k
views
6 answers
40 votes
go_editor asked Apr 21, 2016
11,994 views
An undirected graph $G(V,E)$ contains $n \: (n>2)$ nodes named $v_1,v_2, \dots, v_n$. Two nodes $v_i, v_j$ ... $ to $v_6$ in the MST of previous question with $n=10$ is$11$25$31$41$
5.7k
views
2 answers
18 votes
go_editor asked Apr 21, 2016
5,704 views
Consider the following recursive C function that takes two arguments.unsigned int foo(unsigned int n, unsigned int r) { if (n>0) return ((n%r) + foo(n/r, r)); else return 0; ... text{foo}$ when it is called as $\text{foo(513, 2)}$?$9$8$5$2$
7.7k
views
2 answers
26 votes
go_editor asked Apr 21, 2016
7,736 views
Consider the following circuit involving three D-type flip-flops used in a certain type of counter configuration.If all the flip-flops were reset to $0$ at power on ... $ generated by the counter?$3$4$5$6$
24.7k
views
6 answers
58 votes
go_editor asked Apr 21, 2016
24,674 views
Consider a network with five nodes, $N1$ to $N5$, as shown as below.The network uses a Distance Vector Routing protocol. Once the routes have been stabilized, the distance ... to $N1$ in the distance vector of $N3$ ?$3$9$10$ $\infty$