Situations not to use recursion:
- recomputation of values (fibonacci, factorial, GCD)
- exhaust memory very quickly
Advisable to use iteration or memoization, instead, if you are so keen and persistent to implement recursion.
Sunday, August 23, 2009
Recursion vs iteration
Email the blog author at: nicholaskeytholeong [at] gmail [dot] com
Labels:
Algorithms,
General Knowledge
Subscribe to:
Post Comments (Atom)
I really like recursion. Some algorithms can be really more elegant using it. Most problems that arise are really simple to fix. Like memory exhaustion. Unless you are dealing with mobile applications, spending some Kb on the stack for more method calls shouldn't bother. Of course, passing arrays by copy (or big structs - on C) would exhaust your memory. But if you use pointers (or references) it is no big deal.
ReplyDelete