Beruflich Dokumente
Kultur Dokumente
Adaptable Priority 3 a
A priority queue stores Priority Queue ADT:
a collection of entries insert(e)
Queues
inserts entry e
Typically, an entry is a removeMin()
pair (key, value), where removes the entry
the key indicates the with smallest key
priority min()
returns, but does not
The priority queue is remove, an entry
5 g 4 e
associated with a with smallest key
comparator C, that size(), empty()
compares two entries
© 2010 Goodrich, Tamassia Adaptable Priority Queues 1 © 2010 Goodrich, Tamassia Adaptable Priority Queues 2
© 2010 Goodrich, Tamassia Adaptable Priority Queues 5 © 2010 Goodrich, Tamassia Adaptable Priority Queues 6
Coat claim check In turn, the position (or array cell) stores the entry
Valet claim ticket Back pointers (or ranks) are updated during swaps
Reservation number header nodes/positions trailer
Main idea:
Since entries are created and returned from the
data structure itself, it can return location-aware 2 c 4 c 5 c 8 c
entries, thereby making future updates easier
entries
© 2010 Goodrich, Tamassia Adaptable Priority Queues 7 © 2010 Goodrich, Tamassia Adaptable Priority Queues 8
Heap Implementation Performance
A location-aware heap 2 d
Improved times thanks to location-aware
entry is an object
storing 4 a 6 b entries are highlighted in red
key Method Unsorted List Sorted List Heap
value size, empty O(1) O(1) O(1)
position of the entry in insert O(1) O(n) O(log n)
the underlying heap
In turn, each heap
min O(n) O(1) O(1)
position stores an removeMin O(n) O(1) O(log n)
entry remove O(1) O(1) O(log n)
Back pointers are replace O(1) O(n) O(log n)
8 g 5 e 9 c
updated during entry
swaps
© 2010 Goodrich, Tamassia Adaptable Priority Queues 9 © 2010 Goodrich, Tamassia Adaptable Priority Queues 10