next up previous
Next: Up: Previous:

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.


next up previous
Next: Up: Previous: