Simply said, tail recursion is a recursion where the compiler could replace the recursive call with a "goto" command, so the compiled version will not have to increase the stack depth.
Sometimes designing a tail-recursive function requires you need to create a helper function with additional parameters.
For example, this is not a tail-recursive function:
But this is a tail-recursive function:
because the compiler could rewrite the recursive function to a non-recursive one, using something like this (a pseudocode):
The rule for the compiler is very simple: When you find "", replace it with "". But this can be done only if the value returned by the recursive call is returned directly.
If all recursive calls in a function can be replaced like this, then it is a tail-recursive function.
answered Jan 10 '13 at 14:57
- How do I make money while travling
- Is CIAA working properly in Nepal
- What is anti ackerman steering geometry
- How much does Yoast premium cost
- How does one get into the CIA
- Who is better between M10 and CR7
- Is the following understanding of entropy correct
- How safe is Bangalore
- What exactly makes a heavy nucleus unstable
- Are you going to be broke bankrupt
- What are the best alternatives for Prezi
- What is end to end testing
- What books should I follow for MRCS
- Are sarees worn in Bali
- Does aggravation increase blood pressure
- Why is television advertisement expensive
- Whats in it for men in marriage
- What makes you use custom wristbands
- Should colleges pay students
- How often do cis women get misgendered