




















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















































Two kinds of priority queues:
isEmpty size add/put an element into the priority queue get element with min priority remove element with min priority
Two good implementations are heaps and leftist trees.
isEmpty, size, and get => O(1) time
put and remove => O(log n) time where n is the size of the priority queue
Sorting
if a min priority queue is used, elements are extracted in ascending order of priority (or key) if a max priority queue is used, elements are extracted in descending order of priority (or key)
Sorted Array
8 6 2
4 1 Max Priority Queue
Sorted Array
6 2
4 1
8
Max Priority Queue
Sorted Array
(^12)
4 6 8
Max Priority Queue
Sorted Array
1
2 4 6 8
Max Priority Queue
Sort n elements.
n put operations => O(n log n) time. n remove max operations => O(n log n) time. total time is O(n log n). compare with O(n 2 ) for sort methods of Chapter 2.
Uses a max priority queue that is implemented as a heap.
Initial put operations are replaced by a heap initialization step that takes O(n) time.
3 machines and 7 jobs
job times are [6, 2, 3, 5, 10, 7, 14]
possible schedule
A
B
C time ----------->
6
2
3
7
13
13
21
Finish time = 21
Objective: Find schedules with minimum finish time.
A
B
C time ----------->
6
2
3
7
13
13
21
A
B
C
14
10
7 13
15
16
16
Finish time is 16!