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

+3 votes

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

+3 votes

Best answer

- 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.
- 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.

+1 vote

...