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
- According to exercise 6.1-7, an n-element heap has exactly ⌈n/2⌉ leaves.
- Notice that the nodes with height i become leaves after deleting all the nodes with height 0,⋯,i−1.
yi≤n/2i,∀n=0,1,⋯.
The final conclusion follows from the relation xi=⌈yi/2⌉.
No comments:
Post a Comment