Recursive functions tend to fall into certain familiar patterns.
Test the input parameters to see if they represent a special case simple enough to be solved without recursion.
These called base cases.
When this is not a base case, the recursive function
break apart the problem into one or more smaller sub-problems.
Solve the sub-problems via recursive calls.
Combine the sub-problem solutions into a solution for the original problem
Discuss This Page: