next up previous
Next: Pseudocode Up: l3 Previous: Exercise 7.1-2

Maintaining the Heap Property



Heapify(A,i)



\psfig{figure=figures/f3-3.ps,width=4in,height=3in}

Notice that if A[left(i)] $>$ A[i] or if A[right(i)] $>$ A[i] or both (take largest) then swap and recurse until recursion bottoms out at bottom of heap.


next up previous
Next: Pseudocode Up: l3 Previous: Exercise 7.1-2