• We hope you have a fantastic holiday season to close out 2025! Thank you all so much for being part of the Tom's Guide community!

When not to use recursion

You don't need to use recursion. Anything that is done with recursion can be done iteratively. The reason recursion is usually not a good idea is that the system stack is limited in size where as a stack that you create uses normal system memory.
 
Mmmmm.... Tasty stack overflow exceptions! :)

Personally, the only time i use recursion is when a recursive solution will be significantly easier to code/understand then the alternative, but that doesn't come up super often (mainly navigating through trees and the such.)
 
Rather depends upon which language you are using. In some - LISP springs to mind - recursion is the most natural and efficient way to solve a problem. In others, such as C++ it doesn't come quite so naturally; but it can still be a very efficient technique if used wisely.

As kyeana says, something like navigating through trees or enumerating directories. For example, if you were writing a backup program that needed to process every directory and file on a hard disk then recursion would be a very natural approach.