What Sorts of Algorithms and Data Structures are Useful to Game Programmers?

Started by
17 comments, last by archanian 11 years, 5 months ago
Hello to you all. I purchased the book "Introduction to Algorithms" because I'd like to get a better understanding of the sorts of algorithms and data structures that are used in game programming. The first thing that I noticed about the book is that it is HUGE. There's no way I could just sit down and read this thing from cover to cover, and even if I did I would hardly be able to retain all of that information.. I plan on going through all of the sorting algorithms since the book mentions that they are used by many of the other algorithms, and I am already familiar with linked-lists. What other algorithms and data structures are common in game programming?
Advertisement
Some off the top of my head that I've found useful to learn:

- 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
Well, you'll find all sorts of neccessities in games programming so my suggestion is learn them all - eventually. Most CS courses will build up from the basics (which archanian listed pretty well).

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.

I Create Games to Help Tell Stories

Sorry but I disagree.

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.

Previously "Krohm"

Game programmers use every algorithm and data structure. An unhelpful statement, but true.

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.
May I suggest looking through the book "Data Structures for Game Programmers" :)

Beginner in Game Development?  Read here. And read here.

 

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.
Get familiar with graphs and trees, most spacial algebra, coordinate spaces, translation, rotation, scale, cinematic physics, smart pointers are useful but expensive, there is nothing like knowing how to be careful with dynamic memory, state machines... profiling and debugging tools & techniques...
Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272


Oh, also get a good grip on recursivity and asynchronous execution, they are tough topics many people crash against sooner or later
Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272



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.

So, that's an interesting point (not necessarily one that I agree with, but still).

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. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement