Sign in with
Sign up | Sign in
Your question

When not to use recursion

Last response: in Work & Education
Share
February 17, 2013 9:25:13 AM

Hello,
sir i want to know when not to use recursion.

More about : recursion

February 21, 2013 11:28:07 PM

Recursion can get dangerous. Like many things, it is a tool, just don't abuse it.

Each function/method call does go on the stack, so don't use recursion for anything that may make many calls.
February 24, 2013 10:35:32 PM

Rudra123 said:
Hello,
sir i want to know when not to use recursion.

Wrong question.

You should be asking "When would I use recursion?"

Recursion should be used only in moderation, and only when an exit condition can be clearly defined, so as to avoid infinite recursion. Study the 'quicksort' algorithm for an example of how to use recursion properly. This is a good example because the same sort can also be written iteratively. Both have their uses.
!