Skip to content
Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Complexity Theory: 8 Things a Game Programmer Needs to Know

elbeno, 29 November, 200829 November, 2008
  1. For the most part, forget about space complexity. Time complexity is the important one. You can often trade off time for space, though, so be aware of how much you’re using.
  2. O(1), or constant time, is the best option: if you know the array index, great! Unfortunately, hash tables usually incur a space penalty. Beware of poor hashing.
  3. O(log n) is the next best option. Binary search. Not that common, though.
  4. O(n) is not bad, if you have a smallish set of things to iterate through. Or even if you have a largish set and chopping it down would be expensive. O(n) also can be very cache friendly, which can actually put its performance up there with cleverer algorithms. Beware of trying to improve O(n) if it’s going to be unfriendly to your cache. For this reason, and because it’s super easy to think about, O(n) is your bread and butter; to optimize O(n), most of the time go to a hash table.
  5. O(n log n) is usually only encountered in sorting, and is fine for a general purpose sort. But think about a radix sort for large data sets like scene objects.
  6. O(n²) is getting quite bad, and should only be used in the runtime when there is no alternative. AI routines are often offenders, so look at how to cut down the search space in at least one dimension.
  7. O(n³) is too bad for anything runtime; OK for offline processing.
  8. Don’t even think about anything higher order, unless it’s really necessary for your game AND you’re precomputing offline.
Uncategorized

Post navigation

Previous post
Next post

Related Posts

4th Round Roddick

17 June, 2005

If everything goes according to seedings. Nadal could be the QF, but I'm not sure he's proven on grass. Looks like Roger from the other half of the draw. Unless Lleyton can turn something around, but these days he's looking like a spent force.

Read More

the scanner works

14 June, 2007

Score one for Ubuntu. Plug in scanner, fire up xsane, everything's happy.

Read More

Flagrant System Error

9 September, 2006

I don't know what you did, moron, but you sure screwed everything up good. What's going on with Livejournal lately? I'm warning you now, LJ, if you go “Best viewed with Internet Explorer” I'm outta here.

Read More

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

©2026 Why is a raven like a writing desk? | WordPress Theme by SuperbThemes