Heaps: Presentation For Use With The Textbook, by M. T. Goodrich and R. Tamassia, Wiley, 2015
Heaps: Presentation For Use With The Textbook, by M. T. Goodrich and R. Tamassia, Wiley, 2015
Heaps: Presentation For Use With The Textbook, by M. T. Goodrich and R. Tamassia, Wiley, 2015
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
q A priority queue stores a q Additional methods
collection of entries n min()
q Each entry is a pair returns, but does not
(key, value) remove, an entry with
smallest key
q Main methods of the Priority
n size(), isEmpty()
Queue ADT
q Applications:
n insert(k, v)
inserts an entry with key k n Standby flyers
and value v n Auctions
n removeMin() n Stock market enigines
removes and returns the
entry with smallest key
depth keys
0 1
1 2
h-1 2h-1
h 1
(2, Sue)
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