Heap
Heap
Heap
Heaps
xkcd. http://xkcd.com/835/. “Tree.” Used with permission under Creative Commons 2.5 License.
© 2015 Goodrich and Tamassia Heaps 1
Recall Priority Queue Operations
Additional
A priority queue
methods
stores a collection of entries
min()
Each entry is a pair
returns,
(key, value)but does not remove, an entry with smallest key
size(), isEmpty()
Main methods of the Priority Queue ADT
Applications:
insert(k, v)
Standby
inserts anflyers
entry with key k and value v
Auctions
removeMin()
removes
Stock and returns
market eniginesthe entry with smallest key
depth keys
0 1
1 2
h-1 2h-1
h 1
(2,
Sue)
(5, (6,
Pat) Mark)
(9, (7,
Jeff) Anna)
2 1
5 1 5 2
9 7
z 6 9 7
z 6
7 5
5 6 7 6
w w
9 9
16 15 4 12 6 7 23 20
25 5 11 27
16 15 4 12 6 7 23 20
25 5 11 27
16 15 4 12 6 9 23 20
15 4 6 23
16 25 5 12 11 9 27 20
15 4 6 23
16 25 5 12 11 9 27 20
4 6
15 5 8 23
16 25 7 12 11 9 27 20
4 6
15 5 8 23
16 25 7 12 11 9 27 20
5 6
15 7 8 23
16 25 10 12 11 9 27 20