Skip to content

Instantly share code, notes, and snippets.

@john-nash-rs
Created April 28, 2018 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john-nash-rs/6ae47cdd32d0d69ada762cfda43f08dd to your computer and use it in GitHub Desktop.
Save john-nash-rs/6ae47cdd32d0d69ada762cfda43f08dd to your computer and use it in GitHub Desktop.
max-heapify(A,i){
index_of_left_child = left(i);
index_of_right_child = right(i);
heap_size = number_of_elements_in_heap(A)
if((index_of_left_child <= heap_size) && (A[index_of_left_child] > A[i]))
largest = index_of_left_child
else
largest = i
if((index_of_right_child <= heap_size) && (A[index_of_right_child] > A[i]))
largest = index_of_right_child
if(i != largest)
exchange(A[i], A[largest])
max-heapify(A,largest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment