Professional Documents
Culture Documents
007
007
Let, N(T) be the number of nodes in a non-empty binary tree, and P be the proposition
we want to prove.
Inductive base: If T consists of a single root node r, (base case for a non-empty
binary tree), then according to the definition of the height of a binary tree, h(T) = 0.
Therefore, N(r) = 1 ≤ 20+1 – 1 ≤ 2h(r)+1 – 1
So, P(r) holds.
Inductive hypothesis: In the recursive step of the definition of a non-empty binary
tree, T may consist a root node r pointing to 1 or 2 non-empty binary trees T L and TR.
Without loss of generality, we can assume that both TL and TR are defined, and we
assume P(TL) and P(TR).
Also, let us assume h(TL)≥h(TR), without loss of generality, because the case of
h(TL)<h(TR) is symmetric to the case of h(TL)>h(TR), according to the definition of a
non-empty binary tree.
Inductive step: We have to prove that P(T) must hold.
h(T) = max(h(TL), h(TR)) + 1 [Definition of the height of a non-empty binary tree]
⇒h(T) = h(TL)+1 [h(TL)≥h(TR)]
Now,
N(T) = 1 + N(TL) + N(TR) [Definition of a non-empty binary tree]
⇒N(T) ≤ 1 + 2h(TL)+1 – 1 + 2h(TR)+1 – 1 [P(TL) and P(TR)]
⇒N(T) ≤ 2h(TL)+1 + 2h(TR)+1 – 1
⇒N(T) ≤ 2h(TL)+1 + 2h(TL)+1 – 1 [h(TL)≥h(TR), so 2h(TL)+1≥2h(TR)+1]
⇒N(T) ≤ 2(2h(TL)+1) – 1
⇒N(T) ≤ 2(2h(T)) – 1 [h(T) = h(TL) + 1]
⇒N(T) ≤ 2h(T) + 1 – 1