Recursion in games

Started by
35 comments, last by Sandman 18 years, 7 months ago
Don't understand trees yet... but I plan on finishing my 2nd C++ book in a month, then get code complete.

After that I'll dive into the frustrating division of DirectX or OpenGL... whichever one seems best at the time.
Advertisement
Quote:Original post by TommySauder
So far, just factorials!


Just factorials, hmm?

Do you want to know true algorithms that are very important in several areas of Comp Sci that use recursion (even if they are not recursive)?

Almost all graph algorithms!
Djikstra's shortest path algorithm gives you a recursion tree from the destiny to where you had started... And as for Djikstra, several other algorithms use that kind of recursion...
TommySauder,
I had a similar problem with understanding recursion when I first
came across it. Here is what I learned...
1. Anything that can be done with recursion can be done with iteration.
2. But some problems lend themselves toward recursion. These problems often
involve a lot of repetition governed by a few simple rules.
3. I didn't fully grasp it until I found a real world application where
recursion was the simplest solution (namely binary tree traversal in my case).
Well, maybe the quickest and easiest way to fully understand the potential of recursion is to look at some functional language... Look at some Haskell or Lisp and you'll see all the beauty of recursion! xD
Quote:Original post by TommySauder
Just wondering if there's an actual use to recursion in games... seems kinda pointless and a complete waste of memory+cpu power.


Recursion can simplify code, making hundred line algorithms into 20 line algorithms. Sometimes(not too often) it's the recursive algorithms that run faster than non-recursive due to less instruction generation
ok, I have a question...

Should I study recursion in depth before I get into an API, either DX or OpenGL?

or will it come to me as I study the API? Because I dont want to get frustrated and just quit with everything again.

If so, is there an intermediate book that will teach how to use recursions in depth?
Quote:Original post by TommySauder
ok, I have a question...

Should I study recursion in depth before I get into an API, either DX or OpenGL?

or will it come to me as I study the API? Because I dont want to get frustrated and just quit with everything again.

If so, is there an intermediate book that will teach how to use recursions in depth?


I wouldn't worry about it too much. Just practice writing a couple of simple functions using recursion to get an idea of how they work, and that should be fine. They're not that hard to write, in fact they're usually easier than their iterative counterparts. You just have to make sure they terminate at some point, preferably before you run out of stack space.

You don't *need* to know anything about recursion to use a graphics API like DirectGraphics or OpenGL. However, for some of the more fancy techniques such as scenegraph traversal and collision detection and so forth, recursion is very useful.

This topic is closed to new replies.

Advertisement