Professional Documents
Culture Documents
Root: 1
Step 2: Compare the new node with its parent. If it is smaller than
the parent, swap it with the parent.
Step 2: Replace the minimum node with the last leaf node
increaseKey
increase the value at a specific position by a specific amount.
Again this could cause a violation. This one is re-heapified by
doing a percolate-down.
remove
remove a node from a specific position in the heap. Done by
performing decreaseKey followed by a regular deletion.
Other Heap Operations
buildHeap
This can be done by performing successive inserts.
or
temp = array[r]
while ( r * 2 <= n )
c = r * 2
if c != n AND array[c+1] < array[c]
increment c by 1
endif
r = c
endwhile
array[r] = temp
Heap Pseudocode
percolate up psuedocode:
Increment size by 1
Set h equal to sizw
array[r] = insertItem