Wednesday, June 18, 2008

Heap Extract-Maximum

Heap Extract-Maximum (H)

The above Function removes and returns the element having largest key value from the given heap. The heap-size is decremented by 1 after removing the element. The Function calls ‘Heapify’ for fixing the new heap.
Step 1 Is empty ?
If (heap-size [H] < 1) then
message “underflow heap”
goto step 2
Step 2 Initialization, and adjusting the volues.
set max  H[1]
set H [1]  H [heap-size [H] ]
set heap-size [H]  heap-size [H] – 1
Step 3 fixing new heap
call to Heapify (H, 1)
Step 4 return value at the point of call
return (max)

No comments: