next up previous
Next: Insert Up: CSE 2320: Algorithms and Previous: Priority Queues

Application: Job Scheduling



Support insertion of prioritized jobs in queue.

Support extraction of highest priority job from queue.



Using heaps:

Max(S)
= A[1], $\Theta(1)$
ExtractMax
O(lgn), First 3 lines $\Theta(1)$, fourth line O(lgn)

ExtractMax(S)
1
$\;\;\;\;\;$max = A[1]
2
$\;\;\;\;\;$A[1] = A[HeapSize(A)]
3
$\;\;\;\;\;$HeapSize(A) = HeapSize(A) - 1
4
$\;\;\;\;\;$Heapify(A,1)
5
$\;\;\;\;\;$return max



This corresponds roughly to one iteration of HeapSort.



Copyright © 1998 The University of Texas at Arlington