Created
November 5, 2013 18:42
-
-
Save DapperJohn/7323901 to your computer and use it in GitHub Desktop.
PseudoCode for two
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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