What is tail recursion?
With tail recursion, a recursive function is called at the end of a particular module of code and not in the middle. A function is recursive when it calls itself. This programming concept is often useful for self-referencing functions and plays an important role in programming languages such as LISP.
In computer programming, a function that calls itself either directly or indirectly is a recursive function. If this call is made at the end of the function, it is called tail recursion. Typically, other calculations or procedures are performed before the recursive call.
Tail recursion usually occurs when a recursive function call is made, then ends and has nothing to do after the recursive call is made. The benefits of this approach include less stress on holding a stacking frame, as well as code readability. Programmers and designers sometimes use tail recursion to tweak their code and maximize efficiency.