Skip to content

Instantly share code, notes, and snippets.

@DapperJohn
Created November 5, 2013 18:42

Revisions

  1. JohnTrib3 created this gist Nov 5, 2013.
    32 changes: 32 additions & 0 deletions PseudoTwo
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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);
    }