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

Meme me a meme

25 June, 2005

This one for all of my 3 readers. 1. Put your playlist on shuffle. 2. Post the first lines to the first 10 songs to come up (along with these instructions). 3. Have people guess the songs and artists in comments to the post. Skip over Instrumental/Non-English/Extremely obscure/etc. Also, songs…

Read More

Livejournal makes me sad…

12 August, 2004

LJ, please drop the ActiveX controls and support a decent browser like FireFox! I try to avoid Internet Exploder… In other news, Karaoke Revolution 2! Yes, I'm not afraid to admit I am a sometime fan of Britney Spears. Well, what's not to like? Current Music: MMORadio (a bit), my…

Read More

Tennis season

25 May, 2005

Tennis season is here! OK, I know it never goes out of season, but I can never be bothered with the Australian Open. And the US Open is an afterthought. No; the next 6 weeks are the good stuff. French Open, a couple of weeks of in-between tournaments, then Wimbledon….

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