New Reply

Recursive vs iterative approach

 
Share Thread Thread Tools
Nov7-12, 10:50 PM   #18
 

Recursive vs iterative approach


Quote by Avichal View Post
Why is recursion sometimes easier that iteration. Programs like n-queens and knights tour are easy using recursion but I struggle making them using iteration.

So what advantage does recursion offer in such cases. Why its easier to think recursive in some cases?
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?
 
Nov8-12, 04:49 PM   #19
 
Recognitions:
Homework Helper Homework Help
Quote by Avichal View Post
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
 
New Reply
Thread Tools


Similar Threads for: Recursive vs iterative approach
Thread Forum Replies
Iterative method Precalculus Mathematics Homework 3
Which approach is nicer? UK MEI approach? American approach? Academic Guidance 0
iterative map in mathematica Math & Science Software 5
Iterative Methods Calculus & Beyond Homework 6
Iterative routines General Math 13