Recursion (computer science): Difference between revisions

Content deleted Content added
mNo 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]], 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.
===Recursively definedRecursive functions===
{{main|recursive function}}
Functions whose domains can be recursively defined can be given recursive definitions patterned after the recursive definition of their ___domain.