Recursion (computer science): Difference between revisions

Content deleted Content added
No edit summary
Line 50:
In this particular example the iterative implementation is slightly faster in practice than the recursive one. (Note that an even faster implementation for the ''Factorial'' function is that of using a [[lookup table]].) There are other types of problems that seem to have an inherently recursive solution, i.e. they need to keep track of prior state. One example is [[tree traversal]], which is possible to implement iteratively with the help of a [[Stack (data structure)|stack data structure]], but the need for the stack arguably defeats the purpose of the iterative solution. Another possible reason for choosing an iterative rather than a recursive algorithm is that in today's programming languages, thread stacks are often much smaller than memory available in the heap, and recursive algorithms tend to require more stack space than iterative algorithms.
===Recursion vs. Iteration ===
While recursion can simplify the solution of a problem, often resulting in shorter, more easily understood source code, it is often less efficient, in terms of both time and space, than iterative solutions. There are some methods to convert recursive algorithm into an iterative algorithm using a loop and branching structure. ''''''I added something on the end of Recursion''''''
 
==Recursive functions==