6.5-8
The operation HEAP-DELETE.A; i / deletes the item in node i from heap A. Give
an implementation of HEAP-DELETE that runs in O.lg n/ time for an n-elementmax-heap.
Solution
1. Find the any leaf of the subtree rooted at A[i], as A[j]. (Complexity, lg(n) )
find-leaf(A, i)
i = i*2
if( i>=length){
return i;
}
return find-leaf(A, i)
2. Put put A[j] at A[i]
3. Let the new A[i] sink down according to the heap condition.