Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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 deques don't swap an item in index a with index b in constant time?

share|improve this question
    
Deque stands for double-ended-queue. –  Brian Jan 14 '13 at 15:35

1 Answer 1

up vote 10 down vote accepted

You are right that it would not be possible to make an efficient heap implementation on top of a doubly linked list. However, deques aren't doubly linked lists; they are random access containers. deques are able to swap an item in index a with index b in constant time. See the SGI documentation for deques.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.