A heap (balanced binary tree) is a tree that carries for each parent (node) a maximum of
We give a short proof sketchfor this by:
(a) deriving the general formula of such a "worst case" balancing operation (root to leave!)
(b) show that the formula has a boundary of
With
-
Assuming the tree has
$n+1$ nodes ($i=0,...,n$ ), given by
$i=0$ with$2^{0}=1$ node
$i=1$ with$2^{1}=2$ nodes
$...$
$i=n$ with$2^{n}$ nodes -
If we balance the worst case path (root to leave) we must sum all possible levels given by
$\displaystyle\sum_{i=0}^{n}2^i$
We set this formula to:(1)
$\displaystyle\sum_{i=0}^{n}2^i=2^{n+1}-1$ and proof it next, by induction.
-
START
$n=0$ gives$1=2^{0}=1=2^{0+1}-1=2^{1}-1=1$ ASSUMPTION
By START holds (1), hence we assume (1) also holds for general$n$ .INDUCTION
To show that (1) also holds for$n$ $\rightarrow$ $n+1$ , we must show that we fulfill
$\displaystyle\sum_{i=0}^{n+1}2^i=2^{n+2}-1$ Rewriting the sum we get
$\displaystyle\sum_{i=0}^{n}2^i+2^{n+1}=2^{n+2}-1$
and we know that for the left sum we can use (1), hence we get
$(2^{n+1}-1)+2^{n+1}=2^{n+2}-1$ now rearranging left side hand we get
$2^{n+1}+2^{n+1}-1=2^{n+2}-1$ which gives
$2*2^{n+1}-1=2^{n+2}-1$ and finally
$2^{n+1}-1=2^{n+2}-1$ to proof that (1) holds.
We assume
Now to find height
which gives
then applying the logarithm yields
now by ignoring constants as
we see that