In the C++ STL, priority_queue
(heap) can be used with any underlying container, such as a deque
. How does the implementation stay O(log n)
if deque
s don't swap an item in index a
with index b
in constant time?
Asked
Active
Viewed 1,391 times
4

Jakob Weisblat
- 699
- 5
- 19
-
Deque stands for double-ended-queue. – Brian Jan 14 '13 at 15:35
1 Answers
10
You are right that it would not be possible to make an efficient heap implementation on top of a doubly linked list. However, deque
s aren't doubly linked lists; they are random access containers. deque
s are able to swap an item in index a
with index b
in constant time. See the SGI documentation for deque
s.

per.eckerdal
- 116
- 1
- 2