# How to do this induction proof?

This recursive formula: calculates the amount of possible, structurally different, binary trees for a specific height.

I need to prove it by induction.

The base case is clear: for $h=1$ we get only one tree with one node.

So, suppose the formula holds for some tree of height $h$.

Now I need to prove, that it also holds for a tree of height $h+1$.

From here, I don't know how to continue.

I am familiar with induction and I did it many times, but in this case it seems somehow different.

How does this proof work?

EDIT:

$h(0)$ is $1$

• Hello, my CS-playing friend - I'm not previously familiar with the concept of structurally different binary trees, which seems necessary to perform the induction step. – Chris Jan 28 '17 at 19:22
• @Chris: Hello to you! For example if the height is $2$ you can build three structurally different binary trees: one with three nodes and two with two nodes (root, right child and root, left child) – de_dust Jan 28 '17 at 19:27

The terminology in this answer might be kind of tough to digest, but the idea is actually really simple. It can definitely be rephrased using "strong" induction.

It's really helpful to think of the ordered product $$f(i)\cdot f(j)$$

as the number of ways of creating - starting from a single root node - a left subtree of height $i$, not including the root node, and a right subtree of height $j$, also not including the root node. Therefore $f(i) \cdot f(j)$ will give us all the trees whose left subtrees (including the root node!) have height $i + 1$, and whose right subtrees have height $j+1$ (again, including the root node).

Counting how to do this for all $i, j \ge 0$, with at least one of $i$ or $j$ equal to $h - 1$, will tell us how to make all trees with overall height $h$ - since each tree of height $h$ is precisely just a root node and two subtrees, one of which has height $h-1$.

My point is that, if you actually look at it carefully,

$$\left[2\sum_{i = 0}^{h-2}f(i)\cdot f(h-1)\right] + f(h-1)^2 = \sum_{i = 0}^{h-1}f(i)\cdot f(h-1) + \sum_{j= 0}^{h-1} f(h-1) \cdot f(j)$$

and the right-hand side is going to give you all of the ways of making trees, starting from a root node, with subtrees of size $i$ or $j$, and $h-1$.