 Quote by Avichal
As I asked earlier, why is recursion sometimes much easier to implement than iteration even though it seems like both methods are almost the same?
|
It mostly depends if the algorithm you've choosen is more oriented to an iterative or recursive implementation. The directory / tree scan algorithm example I mentioned earlier is more oriented to a recursive implementation because the nature of the structure of the directory / tree is recursive. Fibonacci or any summation or product series can be implemented either way, but usually an iterative approach will be more efficient. A merge sort can be implemented bottom up using iteration, or top down using recursion, but the bottom up iterative approach is more efficient. If you're not familiar with merge sort, wiki article:
http://en.wikipedia.org/wiki/Merge_sort