Tail Recursion in Data Structure
Tail Recursion:
A recursion function is said to be Tail Recursion if there are no pending operations to be performed on return from a recursive call.
Consider the function fnFact() of the algorithm, note that there is a pending operation, namely multiplication to be performed on return from each recursive call. Whenever there is a pending operation, the function says non-tail recursive. The fnFact() function can re-write in a tail-recursive way as shown below:
Algorithm:
Algorithm fnFact(n, result) { if(n==0 || n==1) return result; else return fnFact(n-1, n*result); }