Recursion - rFronteddu/general_wiki GitHub Wiki
Description
Recursion is an approach to solve a problem using a function that calls itself as a subroutine.
To a void an infinite loop a recursive function must:
- Simple base case (or cases) - terminating case that does not use recursion
- Set of rules (recurrence relation) that reduce all the other cases to the base one
Unfolding Recursion
Example:
There are two important things to figure to implement a recursive function:
- Recurrence Relation: The relation between the result of a problem and the result of its subproblems.
- Base Case: The case where one can compute the result directly, also called the bottom case.
Divide&Conquer VS. Backtracking
- d&c often has a sole solution.
- Each step in d&c is indispensable to build a final solution, in bt, they are often attempts.
- In bt, we often don't know the exact/favorite path a priori.