Algorithm 2 Max Heap Delete

1: // a lazier and slower version

2:procedure MaxHeapDelete(A,iA, i)

3:HeapIncreaseKey(A,i,A, i, \infty)

4:HeapExtractMax(AA)

5:end procedure

6:

7: // a faster but more complex version

8:procedure MaxHeapDelete(A,iA, i)

9:if A[i]>A[A.heap-size]A[i] > A[A.\text{heap-size}] then

10:A[i]=A[A.heap-size]A[i] = A[A.\text{heap-size}]

11:MaxHeapify(A,iA, i)

12:else

13:HeapIncreaseKey(A,i,A[A.heap-size]A, i, A[A.\text{heap-size}])

14:end if

15:A.heap-size=A.heap-size1A.\text{heap-size} = A.\text{heap-size} - 1

16:end procedure