



















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















































Array A
Array A
Insert 17
swap
Percolate up to maintain the
heap property
element stored there ).
element stored there ).
Heapify
Heapify(A, i)
l left(i)
r right(i)
if l <= heapsize[A] and A[l] > A[i]
then largest l
else largest i
if r <= heapsize[A] and A[r] > A[largest]
then largest r
if largest != i
then swap A[i] A[largest]
Heapify(A, largest)
Example: Convert the following array to a heap
Picture the array as a complete binary tree:
Array A
Sorted:
Take out biggest
Move the last element
to the root