top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Iteration or recursion, which one is good to use when a problem can be solved by either of them ?

+3 votes
1,005 views

Some problems can be solved by iteration and recursion . Decision to chose either of them is depend on what factors ?

posted Sep 6, 2013 by Ganesh Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
iteration is a performance gain for your computer and recursion is a performance gain for programmer.

2 Answers

+3 votes
 
Best answer
  1. Recursive algorithms tend to require more stack space than iterative algorithms. If the stack limit is too constraining then you will prefer iteration over recursion.
  2. Also iteration is better in performance. Iterative functions are typically faster than their recursive counterparts. So, if speed is an issue, you would normally use iteration.
    Some procedures are very naturally programmed recursively, and all but unmanageable iteratively. So, it is better to go for Iteration.
answer Sep 6, 2013 by Satyabrata Mahapatra
+1 vote

Recursion is costlier (in terms of resource usages) then iteration if everything else is same. Having said that many compilers covert recursive code to iterative as part of optimization so life is easy and you can enjoy the power of recursion in place of using long code of iterative methods.

answer Sep 6, 2013 by Majula Joshi
...