Tail recursion

A recursive method is tail recursive when there is no pending operation to be performed on return. For example, in our factorial code, the returned value is used to multiply with the previous value to calculate the factorial. So, this is not tail recursive. The same goes for the Fibonacci series recursion. If we look at our GCD recursion, we can find that there is no operation to do after the return. So, the final return or base case return is actually the answer. So, GCD is an example of tail recursion. Tail recursion is also a form of linear recursion.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset