What is the no. of distinct binary trees possible with n labeled nodes?
Solution
(2n)!(n+1)!
(Proof to be Added)
What is the no. of distinct binary trees possible with n unlabeled nodes? (No. of structurally different binary trees possible with n nodes)
Solution
If the nodes are similar (unlabeled), then the no. of distinct binary trees will be the above value divided by the no. of distinct permutations possible for a binary tree structure, which will be n! for a tree with n nodes.
(2n)!(n+1)!n!
=2nCnn+1
(This is the nth Catalan number)
What is the no. of distinct binary search trees possible with n nodes?
Solution
Counting the no. of distinct binary search trees possible for n nodes, is similar to counting the no. of distinct binary trees possible for n nodes assuming nodes are unlabeled. Hence, this value will also be
=2nCnn+1
(nth Catalan number)
Alternatively, for each valid binary search tree, we can get n! binary trees by permuting the vertices, of which only 1 permutation is aBST. Hence, the total no. of binary search trees possible with n nodes will be
No. of distinct binary trees with n distinct nodesn!
= (2n)!(n+1)!n!
=2nCnn+1
(nth Catalan number)
(We can also use the fact that for a given tree structure, there can be only 1 BST. Hence, no. of different BSTs with n nodes will be equal to the no. of different binary tree structures possible for n nodes)
174815 total views , 3 views today