Processing math: 100%

Thursday, February 10, 2011

Nodes of height h in an n-element heap


This is exercise 6.3-3 of CLRS version 2.

Question:Show that there are at most n/2h+1 nodes of height h in any n-element heap.

Solution: First some facts
  1. According to exercise 6.1-7, an n-element heap has exactly n/2 leaves.
  2. Notice that the nodes with height i become leaves after deleting all the nodes with height 0,,i1.
Let yi be the total number of elements of the new tree after deleting all the nodes with height 0,,i1, and let xi be the number of leaves of the new tree. Then we have xi=yi/2 by fact #1 and yi+1=yixi by fact #2. Thus we have yi+1yi/2, and this leads to
yin/2i,n=0,1,.

The final conclusion follows from the relation xi=yi/2.

No comments:

Visitors