Counting leafs of a perfect binary tree without knowing number of nodes

graph theorytrees

Is it possible to be able to count the number of leafs in a perfect binary tree where the number of nodes is not given?

I wanted to use the formula $2l-1$ in my proof for how many nodes are in a perfect binary tree but for $l$, I am not sure how to find this value before showing $2l-1$ is the number of nodes.

Should I use induction and rely on the base cases and inductive hypothesis to prove the formula holds instead of trying to find an explicit formula for $l$?

Best Answer

According to wikipedia

https://en.wikipedia.org/wiki/Binary_tree#Common_operations

For a perfect binary tree, $\ell$ (the number of leaves) is $2^h$, where $h$ is the height. (Perfect in this case means that each internal node has exactly two children, and all leaves are at the same depth. If you don't know that the "same-depth" condition is true for your tree, then your question is again unanswerable without further information.)

That formula certainly seems to check out for height $1$, where there's a root and two leaves, since $2 = 2^1$.

In your case, you say that you have $h = 2^{n+1}-1$, so the number of leaves is $$ \ell = 2^{(2^{n+1}-1)}. $$

I personally suspect that your formula for height is messed up, because $2^{n+1}-1$ happens to be the formula for the number of leaves in a tree of height $n$, but I'm gonna have to trust that you mean what you say, so I've written the answer above.

Related Question