• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lride

priority_queue big o notation with vector and deque

10 posts in this topic

What's the big o notation for push() and pop() in priority_queue with vector or deque as its underlying container.
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
0

Share this post


Link to post
Share on other sites
The complexity should be logarithmic in the size of the queue, regardless of which of those underlying containers you are using (but expect a larger constant in front of it for deque). I can try to justify my answer but I don't have the time right now.
0

Share this post


Link to post
Share on other sites
[quote name='Álvaro' timestamp='1353364794' post='5002480']
The complexity should be logarithmic in the size of the queue, regardless of which of those underlying containers you are using
[/quote]
What?!!
Can someone please tell me the pro/cons and big o notation of having which particular underlying containers in a priority_queue[list]
[*]set
[*]vector
[*]list
[*]deque
[/list]
0

Share this post


Link to post
Share on other sites
Talked in IM, it probably isn't homework.

Consider the underlying container.

A set is a tree. What is the complexity of adding and removing from the beginning and end of a tree? At worst you need to shuffle your way back up the tree to balance it.


A vector is an array. What is the complexity of adding and removing from the beginning and end of an array? At worst you need to move every single element in the array over by one space.

A list is a linked list. What is the complexity of adding and removing from the beginning and ending of a list? At worst you need to move some pointers.

A deque is specially designed for this purpose, it is a linked list of arrays. What is the complexity of adding or removing from the endpoints of a list-of-arrays? Endpoint manipulation at worst requires adding a page.
1

Share this post


Link to post
Share on other sites
[quote name='lride' timestamp='1353365896' post='5002486']
[quote name='Álvaro' timestamp='1353364794' post='5002480']
The complexity should be logarithmic in the size of the queue, regardless of which of those underlying containers you are using
[/quote]
What?!!
Can someone please tell me the pro/cons and big o notation of having which particular underlying containers in a priority_queue[list]
[*]set
[*]vector
[*]list
[*]deque
[/list]
[/quote]
I'm pretty sure [font=courier new,courier,monospace]set[/font] and [font=courier new,courier,monospace]list[/font] can't be used in a [font=courier new,courier,monospace]priority_queue[/font], as one of the basic requirements for the underlying storage container of a [font=courier new,courier,monospace]priority_queue[/font] is that it must have random access iterators. On that list, only [font=courier new,courier,monospace]deque[/font] and [font=courier new,courier,monospace]vector[/font] meet that requirement. [font=courier new,courier,monospace]list[/font] and [font=courier new,courier,monospace]set[/font] have bidirectional iterators.

[font=courier new,courier,monospace]vector[/font] and [font=courier new,courier,monospace]deque[/font] allow for constant-time insertion/deletion to/from the end of the container, as well as constant-time random element access. You might be surprised about this for deque, but behind the scenes, it's not using a naive double linked list (as some might believe); rather, it's using a paging technique.

frob obviously wants you to think about it all, so I won't give answers away, but here's some simple answers (but seriously try to think about it and answer frob's questions before peaking):
[spoiler]
[code]
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
[/code]
[/spoiler]
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
[quote name='lride' timestamp='1353384159' post='5002568']
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?
[/quote]

priority_queue implements basically a [url="http://en.wikipedia.org/wiki/Heap_(data_structure)"]heap[/url]. After popping the element, you need to move O(log(n)) elements to fill the tree while keeping the feature that each node is less than its successors.
0

Share this post


Link to post
Share on other sites
[quote name='Álvaro' timestamp='1353388057' post='5002587']
priority_queue implements basically a heap
[/quote]

How is priority_queue implemented as a heap when I'm using a vector or a deque as its internal container?
0

Share this post


Link to post
Share on other sites
[quote name='lride' timestamp='1353421016' post='5002666']
[quote name='Álvaro' timestamp='1353388057' post='5002587']
priority_queue implements basically a heap
[/quote]

How is priority_queue implemented as a heap when I'm using a vector or a deque as its internal container?
[/quote]
A heap is just a way of organizing/ordering the data. [font=courier new,courier,monospace]vector[/font] and [font=courier new,courier,monospace]deque[/font] are just ways of storing (not organizing) the data.
0

Share this post


Link to post
Share on other sites
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 [url="http://en.wikipedia.org/wiki/Priority_queue#Usual_implementation"]here[/url].
2

Share this post


Link to post
Share on other sites
[quote name='Álvaro' timestamp='1353439358' post='5002733']
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 [url="http://en.wikipedia.org/wiki/Priority_queue#Usual_implementation"]here[/url].
[/quote]
Thank you. That cleared up my question.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0