Jump to content

Tail recursion: Difference between revisions

m
no edit summary
m (Links, added example of time difference)
mNo edit summary
Line 1:
[[Category:Encyclopedia]]'''Tail recursion''' is a specific type of [[recursion]] where the recursion call is the last call in the function. Because tail recursive functions can easily and automatically be transformed into a normal [[:Category:Iteration|iterative]] functions, tail recursion is used in languages like [[Scheme]] or [[OCaml]] to optimize function calls, while still keeping the function definitions small and easy to read. The actual optimization transforms recursive calls into simple branches (or jumps) with logic to change the arguments for the next run through the function.
 
The benefits of this optimization are primarily [[System stack|stack]] related. Transforming recursive functions into iterative functions can save memory and time.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.