[Math] Induction Proof Check: For a binary tree T, Prove that the number of full nodes in T is always one less than the number of leaves in T.

computer sciencediscrete mathematicsinductiontrees

This is a slight variant on a very common beginner's problem. I think I've got it figured out, but I wanted to make sure I actually proved what's being asked.

We define a binary tree $T$:
(a) A tree with a single root $r$ is in $T$
(b) From $r$ branches two trees: $T_1$ and $T_2$

A node is full if it contains a non-empty left child and a non-empty right child.

Prove (using induction) that for any tree, the number of full nodes is one less than the number of leaves.


This recurrence relation describes the relationship between a the number of full nodes $F(n)$ and the number of leaves $n$:

$$
F(n) = \left\{
\begin{array}{l l}
1 & \quad \text{if $n = 2$}\\
F(n-1) + 1 & \quad \text{if $n > 2$}
\end{array} \right.
$$

I will now represent this recurrence relation in what I suspect
is its closed form:

$$ G(n) = n – 1 $$

Now, I if can prove that $F(n) = G(n)$, then I have proved that the number of full nodes is always one less than the number of leaves.

Basis:
$ G(2) = 2 – 1 = 1 $ $\checkmark$

Inductive Hypothesis:
$F(k) = G(k) = k – 1$, where $n=k$ , to show:
$F(k+1) = k+1-1 = k$

Inductive Step:

$$\begin{align}
\ F(k+1) & = F((k+1)-1) + 1 \\
& = F(k) + 1 \\
& = G(k) + 1 \\
& = (k – 1) + 1 \\
& = k
& \qquad\square
\end{align}$$

It looks like I've proved that $F(n) = G(n)$, but I feel like I haven't properly associated the original recurrence relation $F(n)$ with the tree itself. I feel like I did, but what do proofs care about my feelings? Does my proof hold?

Best Answer

Proof by induction on the height h of a binary tree.

Base case: h=1

There is only one such tree with one leaf node and no full node. Hence the statement holds for base case.

Inductive step: h=k+1

case 1: root is not a full node.

WLOG we assume it does not have a right child. In this case the number of full nodes and the the number of leaf nodes is equal to the tree which is rooted at at's left child. Since the height of that left subtree is k, by induction the difference should be 1.

case 2: root is full node.

total number of leaf nodes = leaf node in tree rooted at it's left and right.

total number of full nodes = 1 (the root itself) + the number of full nodes to its left and right.

Thus the difference remains 1.

Proved.