Derive the recursive equation for number of binary trees with ‘n’ nodes

combinatoricsinductiontrees

Now I know that the number of binary trees with n nodes is given by (2n!/(n+1)! n!)

How can I derive this using the basic definition of a binary tree, which says that a binary tree is either an empty tree, or a tree with two children which are also trees?

I thought I could use induction, but I couldn't go beyond the base case:

Base case: f(0) = 1 (There is 1 binary tree with 0 nodes).

Also, I am not supposed to know the term (2n!/(n+1)!), I am supposed to derive it. I don't think induction helps for this. From what I know, induction is used to prove something you know is a fact, not derive that fact.

Best Answer

If $f(n)$ is the number of unlabelled binary trees on $n$ nodes, then $f(0)=1=f(1)$. The definition then yields a recurrence: to get a binary tree with $n+1$ nodes, start with a root node and hang from it a left subtree with $\ell$ nodes and a right subtree with $r$ nodes, where $0\le\ell,r\le n$ and $\ell+r=n$. For a given $\ell$ there are $f(\ell)$ possible left subtrees and $f(n-\ell)$ possible right subtrees, and every binary tree with $n+1$ nodes is obtained uniquely in this way, so

$$f(n+1)=\sum_{\ell=0}^nf(\ell)f(n-\ell)\,.$$

This answer shows (with somewhat different notation) how to use generating functions to derive a closed form for $f(n)$.