Heapify

Heapify is the process of creating a heap data structure from a binary tree.

We can create a heap from an array in , and not . The reason is that we are starting from the last value of the heap in the array.

  • Starts from the parent of the last element in the array and iteratively performs the fix-down operation to maintain heap property. fix-down is constant time therefore he overall time is .

Answer from quiz Module 2:

last = floor((n - 2) / 2)
for i from last to 0:
	fix-down(A[i])
end for

Used in Heap Sort.