550 views
3 votes
3 votes

http://gatecse.in/number-of-binary-trees-possible-with-n-nodes/

In the first answer (What is the no. of distinct binary trees possible with n labeled nodes?), 

"An edge can be made either as a left child of a node or as a right child. Hence, for n nodes, we have 2n possibilities for the first edge, 2n−1 for the second edge and so on. Thus, for n−1 edges, the total no. of ways..."

I understood above statement. But if we go on and choose like this, what is the surety that we get a tree? 

As in the above figure(we choose from 4 nodes in the left side to get the graph in right side), the choices allows us to choose like this,we selected n-1 edges,still we didn't get a tree. 

1 Answer

0 votes
0 votes
2n pointers can point to n-1 items... but you are pointing to more items....  you are pointing to n-1 items+NULL+you are pointing to a vertex which is already a child(which violates tree property)  ..
So to include all these, you derive a new formula which will give a bigger num...
But as per our requirement.. our formula is correct.. we have excluded these diagrams while forming the formula.

Related questions

2 votes
2 votes
3 answers
3