Line 5: Line 5:
 
For a binary tree with n nodes, the number of edges is n-1.So, this problem can be reduced to the number of ways in which we can make n-1 edges from n vertices. An edge can be made either as a left child of a vertex or as a right child. Hence, for n vertices, we have 2n possibilities for the first edge chosen, 2n-1 for the second and so on. Thus for n-1 the total number of ways  
 
For a binary tree with n nodes, the number of edges is n-1.So, this problem can be reduced to the number of ways in which we can make n-1 edges from n vertices. An edge can be made either as a left child of a vertex or as a right child. Hence, for n vertices, we have 2n possibilities for the first edge chosen, 2n-1 for the second and so on. Thus for n-1 the total number of ways  
  
= 2n * (2n-1) * (2n-2) * .... * (2n - (n - 2))
+
= $2n * (2n-1) * (2n-2) * .... * (2n - (n - 2))$
= 2n * (2n-1) * (2n-2) * .... * (n + 2)
+
 
 +
= $2n * (2n-1) * (2n-2) * .... * (n + 2)$
 +
 
 
=$ \frac{(2n)!} { (n+1)!}$
 
=$ \frac{(2n)!} { (n+1)!}$
  

Revision as of 13:07, 6 January 2014

What's the number of distinct binary trees possible with n distinct nodes?

Solution

For a binary tree with n nodes, the number of edges is n-1.So, this problem can be reduced to the number of ways in which we can make n-1 edges from n vertices. An edge can be made either as a left child of a vertex or as a right child. Hence, for n vertices, we have 2n possibilities for the first edge chosen, 2n-1 for the second and so on. Thus for n-1 the total number of ways

= $2n * (2n-1) * (2n-2) * .... * (2n - (n - 2))$

= $2n * (2n-1) * (2n-2) * .... * (n + 2)$

=$ \frac{(2n)!} { (n+1)!}$




blog comments powered by Disqus

What's the number of distinct binary trees possible with n distinct nodes?

Solution[edit]

For a binary tree with n nodes, the number of edges is n-1.So, this problem can be reduced to the number of ways in which we can make n-1 edges from n vertices. An edge can be made either as a left child of a vertex or as a right child. Hence, for n vertices, we have 2n possibilities for the first edge chosen, 2n-1 for the second and so on. Thus for n-1 the total number of ways

= $2n * (2n-1) * (2n-2) * .... * (2n - (n - 2))$

= $2n * (2n-1) * (2n-2) * .... * (n + 2)$

=$ \frac{(2n)!} { (n+1)!}$




blog comments powered by Disqus