Share
Explore BrainMass

Heapsort: Heapify

Consider the following definition of HEAPIFY.

HEAPIFY(A, i)
1 l = LEFT(i)
2 r = RIGHT(i)
3 if l < heap-size[A] and A[l] > A[i]
4 then largest = l
5 else largest = i
6 if r < heap-size[A] and A[r] > A[largest]
7 then largest = r
8 if largest != i
9 then exchange A[i] and A[largest]
10 HEAPIFY(A,largest)

What is the effect of calling HEAPIFY(A, i) when the element A[i] is larger than its children?

Solution Summary

It is a very brief answer, explaining the WHY of it as well.

$2.19