Understanding head recursion
Head recursion is when a recursive function calls itself at the beginning of the code block, just after checking for base cases. Since the function is called at the beginning, all deeper recursive calls (till the base case) are finished before its processing begins. The result of each step is often processed using the results from the recursive steps below it, and so head recursion is used in cases where the solution has to be built from bottom to top.
The head recursion pattern is the classification of problems that can be solved using head recursion.
Loading Image
The solution is built from bottom to top during stack unwinding in head recursion.
Liking the course? Check our discounted plans to continue learning.