Proposition: A heap containing n nodes has at most height h=ceil(lg(n+1))
At each level l there are 2l nodes.
The number of internal nodes (i) is at least.
(consider a tree of height 4, level 0, level 1, level 2 are full are full,
of internal nodes, and there must be at least one internal node at level
h-1)
If level h-1 is full, then the sum is
In any case, if a>0 we know
so i = 2h-1
We know from the previous chapter, the number of external nodes in a proper
binary tree is one more than the number of internal nodes.
So we know we are between
2*(2h-1) <= n <= 2*(2h-1) and
2h <= n <= 2h+1
So lg(n+1) <= h