top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

When should we use recursion over iterative method?

+2 votes
507 views
When should we use recursion over iterative method?
posted Oct 9, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Recursion is mainly used to save the lines of code (code re-usability).
For example, while writing a code for tree(data structures), it saves lump-some of lines of code.
It makes a code more modular & optimized.
Recursion should be used where memory (stack) is not a constraint because recursion gives a very hard time to our stack.

Though it is slower than loops, it has its own advantages too. Also debugging becomes difficult while using recursion.

Hope this helps!

answer Oct 9, 2014 by Ankush Surelia
Well explained, I was just thinking what could be the possible reason why someone should use recursion and in the impression that we should always use iterative if possible but I was wrong.
Thank you sir :-)
Similar Questions
+5 votes

Say I have a function which is written in recursive way which is costly way of doing the things. Now I want to convert the recursive function into iterative one. Is there a standard approach which can be applied to all the functions..

+4 votes

Addition to this,

Can we consider "a car a man a maraca" as palindrome string?
Click here To see similar kind of palindrome strings,
Are they really a palindrome?

...