I can't find this anywhere.
I'm guessing linear complexity at worst for push() because it has to search for right place to insert.
Edited by lride, 19 November 2012 - 04:30 PM.
Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 19 November 2012 - 04:21 PM
Edited by lride, 19 November 2012 - 04:30 PM.
Posted 19 November 2012 - 04:39 PM
Posted 19 November 2012 - 04:58 PM
What?!!The complexity should be logarithmic in the size of the queue, regardless of which of those underlying containers you are using
Posted 19 November 2012 - 05:31 PM
Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.
Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.
Posted 19 November 2012 - 07:28 PM
I'm pretty sure set and list can't be used in a priority_queue, as one of the basic requirements for the underlying storage container of a priority_queue is that it must have random access iterators. On that list, only deque and vector meet that requirement. list and set have bidirectional iterators.What?!!The complexity should be logarithmic in the size of the queue, regardless of which of those underlying containers you are using
Can someone please tell me the pro/cons and big o notation of having which particular underlying containers in a priority_queue
- set
- vector
- list
- deque
list-based priority_queue: O(impossible) for everything set-based priority_queue: O(impossible) for everything vector-based priority_queue: O(log(n)) for push/pop deque-based priority_queue: O(log(n)) for push/pop
Posted 19 November 2012 - 11:07 PM
Why would pop() be log n? It's just removing an element from the end. And how does priority_queue have all of its element sorted?
Posted 20 November 2012 - 08:44 AM
A heap is just a way of organizing/ordering the data. vector and deque are just ways of storing (not organizing) the data.priority_queue implements basically a heap
How is priority_queue implemented as a heap when I'm using a vector or a deque as its internal container?
Posted 20 November 2012 - 01:22 PM
Posted 20 November 2012 - 02:50 PM
Thank you. That cleared up my question.In more detail, nodes in a heap can be assigned indices that are small consecutive integers, which makes it possible to use a vector or a deque for storage. Node 0 is the root, nodes 2*i+1 and 2*i+2 are the children of node i, and node (i-1)/2 is its parent. The resulting implementation of a heap is quite efficient, and that's probably how priority_queue is implemented by your library (although there are other possibilities).
You can read more about it here.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.