What Sorts of Algorithms and Data Structures are Useful to Game Programmers?
#1 Members - Reputation: 96
Posted 01 November 2012 - 06:12 PM
#2 Members - Reputation: 241
Posted 01 November 2012 - 09:39 PM
- Stacks & queues
- Linked lists (mostly singly-linked but you may find all the variations useful)
- Trees
- Sorting algorithms of all varieties
- Pathfinding algorithms (A*, Dijkstra's)
- Object pooling
#3 Members - Reputation: 449
Posted 01 November 2012 - 10:41 PM
Really, unless you know what kind of games you are going to be working on, it would be hard to say exactly what you'll need. Problems found in game creation are many and varied - if not just as varied as in any other field, than pretty close to it. Learn a variety of algorithms for a number of different applications (when would you use a stack over a queue?
Yeah, sorry. I know it's a pain in the ass kind of answer, but it's the best and only one I can give. Educate yourself broadly, and know where to go for answers to specific questions (I've forgotten most of what I learned in my CS courses, but I remember where to find it all again!).
Oh, and learn about hashing. Hashing is magical.
#4 GDNet+ - Reputation: 1743
Posted 02 November 2012 - 01:10 AM
Sorting algorithms. Here's what you need to know.
std::sort().
Having spent several months at sorting algorithms, I feel safe stating that this is the only thing I care about sorting as an algorithm book would discuss.
Pathfinding algorithms.
Spending effort on them even before starting is a bit of a stretch. I'm not saying this is not necessary, but you can get a lot of mileage before this becomes a blocking stop.
Object pooling.
Studying that in theory is complete nonsense. Get a real problem first. Profile. Fix (if necessary).
What's really needed? How to build sane code. Documentation, style, engineering, knowledge of real-world problems.
Or more related to implementation: object lifetimes, smart pointers, proper OOP, various code patterns etc.
Edited by Krohm, 02 November 2012 - 01:11 AM.
#5 Members - Reputation: 1867
Posted 02 November 2012 - 01:34 AM
You have to classify the different types of game programming tasks to understand what algorithms and data structures are applicable.
For example, someone implementing a 3D rendering system will use totally different things than the guy writing high-level gameplay logic.
My suggestion: Some tasks in code are FAR more common than others. You can get 80% of any programming job done with nothing but simple lists (std::vector, System.Collections.Generic.List<T>, etc) and map/filter operations (map = convert one list to another by applying a conversion function to each element, filter = return a subset of a list based on a function that tests each element). Learn how to use these well. When you run into a case where performance or memory use is too unacceptable, open your book up and look for something that's specific to your situation.
Edited by Nypyren, 02 November 2012 - 01:40 AM.
#6 Crossbones+ - Reputation: 3305
Posted 02 November 2012 - 01:36 AM
Beginner in Game Development? Read here.
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts ![]()
#7 Crossbones+ - Reputation: 1056
Posted 02 November 2012 - 03:40 AM
Basic algos: at least binary search, breadth-first search. The latter is a simple way to solve a wide range of general problems, including pathfinding. A*, IDA* etc. are more complicated, potentially more efficient ways of solving similar problems but you can look at them later if and when you actually need performance.
For performance you are going to have to learn heaps and hashes.
As an aside, you'll rarely want to use a linked list because the performance sucks in practice. Vectors/arrays are usually the right way even when textbook logic would suggest linked list. A lot of the time you will want to keep these sorted so that you can use binary search on them.
#8 Members - Reputation: 294
Posted 02 November 2012 - 10:31 AM
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
#9 Members - Reputation: 294
Posted 02 November 2012 - 10:36 AM
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
#10 Senior Moderators - Reputation: 4742
Posted 02 November 2012 - 11:17 AM
So, that's an interesting point (not necessarily one that I agree with, but still).What's really needed? How to build sane code. Documentation, style, engineering, knowledge of real-world problems.
Or more related to implementation: object lifetimes, smart pointers, proper OOP, various code patterns etc.
All the things you describe are software engineering topics, whereas the OP's book is intended for courses in computer science. And there is a fair bit of truth to the assertion that in the day-to-day of software development, you'll make much more use of practical software engineering skills than you will of a theoretical computer science background.
But, and to my mind this is fairly important, a good developer has both the practical and theoretical backgrounds, and makes use of both fairly equally. Sooner or later you are going to need to build a cache-optimised graph traversal, or a lockless multi-threaded event dispatch mechanism - and at that point, you'll be feeling the lack of all that computer science knowledge...
Tristam MacDonald - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]
#12 Members - Reputation: 96
Posted 02 November 2012 - 02:24 PM
@Krohm: I'd have to disagree. The "concept x is useless because I've never used it before." argument doesn't hold much water. Unless I'm just misunderstanding your point, in which case I apologize.
#13 Members - Reputation: 615
Posted 02 November 2012 - 03:11 PM
For a game developer, you don't really need to know that in detail. But know how data structures work. For example you should know how trees, linked lists and dynamic arrays work.
And learn to use the interface.
#14 Members - Reputation: 1054
Posted 02 November 2012 - 03:21 PM
-Lists
-Dictionaries
-Stacks and Queues
-Arrays
Dictionaries are pretty much hash tables. If I need to store items and pull them out by some key value, then I use a dictionary. If I just need to store a collection of items, I use a list. I rarely use stacks and queues, but sometimes the occassion pops up where they're useful. Arrays are handy for keeping data continguous in memory (which helps with CPU caching), but I think I recall that C# lists are really just arrays wrapped into a list class. It might be worth looking into that...
I rarely ever use binary trees, but I do use binary space partitioning ideas (for QuadTrees) and recursion.
Since I primarily use dictionaries and look up items by a key, I never need to sort my items.
I think the very core of programming most software is about logically managing lists of data
Hobby: Game Developer
Currently employed as: Sr. Sharepoint Developer in Afghanistan
#15 Senior Moderators - Reputation: 4742
Posted 02 November 2012 - 03:33 PM
Depends on what type of game developer. if you are working on mobile/console, then you are likely going to need to know a whole lot about cache architectures, efficient algorithm design, etc. If you are writing for PC, can probably get away without.For a game developer, you don't really need to know that in detail.
Then you should be learning LISPI think the very core of programming most software is about logically managing lists of data
At least, that's what I find myself doing a lot.
Tristam MacDonald - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]
#16 Members - Reputation: 444
Posted 05 November 2012 - 03:25 PM
Game developers often wear many hats (particularly early in their career) and at some point you will probably be writing a shader, even if it's a simple one. But before anyone will really accept you in this industry (that is to say, hire you) you will need to have made a game or at least a solid demo of a game. The unfortunate truth is you will likely be doing this alone. Get a case of redbull and every programming book you can afford; long nights ahead.
#17 Crossbones+ - Reputation: 3305
Posted 05 November 2012 - 03:51 PM
I've reintroduced myself to a data structure that's simpler but as effective as a binary (search) tree. It's called the skip list.For basic game logic, you need to understand at least basic trees because that's what you need to represent hierarchical things.
Basic algos: at least binary search, breadth-first search. The latter is a simple way to solve a wide range of general problems, including pathfinding. A*, IDA* etc. are more complicated, potentially more efficient ways of solving similar problems but you can look at them later if and when you actually need performance.
For performance you are going to have to learn heaps and hashes.
As an aside, you'll rarely want to use a linked list because the performance sucks in practice. Vectors/arrays are usually the right way even when textbook logic would suggest linked list. A lot of the time you will want to keep these sorted so that you can use binary search on them.
Beginner in Game Development? Read here.
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts ![]()
#18 Members - Reputation: 570
Posted 05 November 2012 - 05:10 PM
Be aware of data structures, but you don't need to go around implementing them until you actually have a use for it.
#19 Members - Reputation: 241
Posted 07 November 2012 - 09:56 PM
I know a lot of programming can be done by just "using what works", but for me it all depends how seriously you want to take your game development. If you want to make a career out of it, you're going to need to know a lot of theory as well as practical experience.






