While searching for some functions in C++ standard library documentation I read that push and pop for priority queues needs constant time.
http://www.cplusplus.com/reference/stl/priority_queue/push/
Constant (in the priority_queue). Although notice that push_heap operates in logarithmic time.
My question is what kind of data structure is used to maintain a priority queue with O(1) for push and pop ?
I assume you are referring to cplusplus.com’s page.
Earlier on the page it says:
So, after the
O(1)push, the data structure has lost its heap property invariant and will then always follow that with anO(log N)call to restore that property. In other words, theO(1)operation is only one part of the entire operation; the full operation isO(1) + O(log N)which is the same asO(log N).I guess the reason they mention that is that priority queue is an adapter and they are trying to emphasize the difference between what the underlying container does vs what the adapter does.