# Tail call A **tail call** occurs when a function calls another function as its last operation. In other words, after the tail call is made, the current function has nothing left to do and can simply return the result of the called function. ## Tail Call Example: Here’s an example in Python: ```python def tail_call_example(n): some_function(n) return another_function(n) ``` In this example, the `tail_call_example` function calls `some_function`, which is not the last thing computed by the function making it a simple call, and `another_function` and immediately returns its result. There’s no additional work to do after the call to `another_function`, making it a tail call. ## Tail Recursiion A **tail recursion** is a specific type of tail call where the function calls itself as its last action. Here’s an example in Python: ```python def factorial(n, acc=1): if n == 0: return acc else: return factorial(n - 1, n * acc) ``` In the above code, `factorial` is tail-recursive because the recursive call to `factorial(n - 1, n * acc)` is the last action performed. The `acc` argument accumulates the result as the function recurses. ### Tail Call vs. Non-Tail Call - **Tail Call**: The call is the last operation in the function. - **Non-Tail Call**: There is additional computation after the call, such as returning the result of an expression. #### Example of Non-Tail Recursive Function: ```python def factorial(n): if n == 0: return 1 else: return n * factorial(n - 1) ``` Here, `factorial(n - 1)` is not the last operation. After the recursive call, the function still needs to multiply the result by `n`, so this is not a tail call. --- Bibliography: - [Tail call - wikipedia.org](https://en.m.wikipedia.org/wiki/Tail_call)