Recursion (computer science): Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Alter: pages. Formatted dashes. | Use this bot. Report bugs. | Suggested by Abductive | #UCB_webform 2497/3849
Recursion versus iteration: I just changed a misspelled period(.) to a comma(,)
Tag: Reverted
Line 268:
 
==Recursion versus iteration==
Recursion and [[iteration]] are equally expressive: recursion can be replaced by iteration with an explicit [[call stack]], while iteration can be replaced with [[tail call|tail recursion]]., Whichwhich approach is preferable depends on the problem under consideration and the language used. In [[imperative programming]], iteration is preferred, particularly for simple recursion, as it avoids the overhead of function calls and call stack management, but recursion is generally used for multiple recursion. By contrast, in [[functional programming|functional languages]] recursion is preferred, with tail recursion optimization leading to little overhead. Implementing an algorithm using iteration may not be easily achievable.
 
Compare the templates to compute x<sub>n</sub> defined by x<sub>n</sub> = f(n, x<sub>n-1</sub>) from x<sub>base</sub>: