I need your help trying to figure out/getting an approach to a simple proof.
Suppose you are given a max-heap with n different elements and x is an element in the heap in deep D (in the tree representing the heap). Now suppose we are preforming a series of DeleteMax operations.
-
What is the maximal number of DeleteMax operations needed to be preformed until x will be extracted out from the heap.
-
What is the minimal number of DeleteMax operations needed to be preformed until x will be extracted out from the heap.
Note:
I believe I did manage to prove the second one by specifing that in case x and his parents are the largest elements in the heap then x will be extracted after D+1 DeleteMax operations (D of them are dedicated to extract his parents).
I just found out that the first one isn’t going very well this way, and I’m not sure what approach do I need to use in order to prove it correctly.
I think you are right. The second case will happpen when only the parents and grandparents of x are greater than x, but not the cousins, uncles, and so on… only the predecessors in a straight line to the root.
The first case will happen when only the children of x are smaller than x. Thus, if the heap has a height H, the maximum will be a full heap of height H minus a full heap of height H-D.