Anonymous user
Category:Recursion: Difference between revisions
m
Should have proofread
(Removed extra sentence and added an example of a non-tail-recursive function becoming tail-recursive) |
m (Should have proofread) |
||
Line 20:
Time is saved because each function return takes a long time relative to a simple branch. This benefit is usually not noticed unless function calls are made that would result in large and/or complex call trees. For example, the time difference between iterative and recursive calls of <tt>fibonacci(2)</tt> would probably be minimal (if there is a difference at all), but the time difference for the call <tt>fibonacci(40)</tt> would probably be drastic.
Sometimes, tail-recursive functions are coded in a way that makes
<pre>function F with arguments
if end condition is met
|