Professional Documents
Culture Documents
Entry and Priority Queue Adts
Entry and Priority Queue Adts
Entry and Priority Queue Adts
Adaptable Priority
Queues
3 a
5 g
4 e
insert(e)
inserts entry e
removeMin()
removes the entry
with smallest key
min()
returns, but does not
remove, an entry
with smallest key
size(), empty()
Example
Example
Locating Entries
Operation
Output
insert(5,A)
insert(3,B)
insert(7,C)
min()
p2.key()
remove(p1)
replace(p2,(9,D))
replace(p3,(7,E))
remove(p4)
p1
p2
p3
p2
p4
p5
(5,A)
(3,B), (5,A)
(3,B), (5,A), (7,C)
(3,B), (5,A), (7,C)
(3,B), (5,A), (7,C)
(3,B), (7,C)
(7,C), (9,D)
(7,E), (9,D)
(7,D)
Location-Aware Entries
key
value
position (or rank) of the item in the list
header
Main idea:
List Implementation
2 c
4 c
5 c
trailer
8 c
entries
Heap Implementation
A location-aware heap
entry is an object
storing
Performance
2 d
4 a
6 b
Method
Unsorted List
size, empty
O(1)
insert
O(1)
min
O(n)
removeMin
O(n)
remove
O(1)
replace
O(1)
key
value
position of the entry in
the underlying heap
8 g
5 e
9 c
Sorted List
O(1)
O(n)
O(1)
O(1)
O(1)
O(n)
Heap
O(1)
O(log n)
O(1)
O(log n)
O(log n)
O(log n)
10