Skip to content

Instantly share code, notes, and snippets.

@DapperJohn
Created November 5, 2013 18:42
Show Gist options
  • Save DapperJohn/7323901 to your computer and use it in GitHub Desktop.
Save DapperJohn/7323901 to your computer and use it in GitHub Desktop.
PseudoCode for two
MinimumHeap(A){
return A[1];
}
ExtractMin(A){
if (heap-size[A] < 1) {
then error ``heap underflow''
min <- A[1]
A[1] <- A[heap-size[A]]
heap-size[A] <- heap-size[A] - 1
}
}
HeapifyMin(A,1){
return min;
}
DecreaseKey(A,i,key)
if key > A[i]{
then error ``new key is larger than current key''
A[i] <- key
}
do{
exchange A[i] <-> A[parent(i)];
i <- parent(i);
} while (i > 1 && A[parent(i)] > A[i]);
MinHeapInsert(A,key){
heap-size[A] <- heap-size[A] + 1
A[heap-size[A]] <- +inf
DecreaseKey(A,heap-size[A],key);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment