Thread: Recursion?
View Single Post
  #21   Spotlight this post!  
Unread 14-12-2003, 16:44
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Re: Recursion?

Quote:
Originally Posted by KenWittlief
but with a well thought out data structure, there is nothing you can do with recursion that you cant do better without it.
That depends entirely on what you mean by "better". If you mean using less stack space, then iterative is definately the way to go. If you mean faster running time, then this just simply isn't true. For example, the recursive quicksort procedure is generally significantly faster than it's iterative counter-part[1,2]. Also, for some algorithms it's next to impossible to write an iterative solution (alpha-beta searching, for example).

At the same time, some problems that may seem recursive (towers of hanoi[3], fibonacci, etc), often have much more elegant and faster iterative solutions.

The reality is that sometimes recursive algorithms are better for a task, and sometimes iterative ones are. Learn how and when to use both, and you'll be a much better programmer because of it.

[1] http://www.mathcs.carleton.edu/cours...aj/algory.html
[2] http://www.mvps.org/vb/hardcore/html...equicksort.htm
[3] http://hanoitower.mkolar.org/shortestTHalgo.html
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php