# 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?

© BrainMass Inc. brainmass.com October 9, 2019, 7:00 pm ad1c9bdddfhttps://brainmass.com/computer-science/computer-systems-organization/heapsort-heapify-elements-104642

#### Solution Summary

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

$2.19