Recurrence
A recurrence is an equation/inequality according to which the
th term of a sequence of numbers is equal to some combination of the previous terms.
There are roughly three methods to solve recurrences:
- Substitution Method: Guessing the closed form using substitution and then prove by induction.
- Recursion Tree: Guessing the closed form using the recurrence tree and then prove by induction.
- Master Theorem: Finding asymptotic bounds of some recurrences using predefined rules.
We will now introduce the last two methods.
Recursion Tree
Recursion Tree
Recursion tree is a tree where:
- Each node represents a single sub-problem along with the cost of the particular sub-problem.
- An edge from node
to node means that the sub-problem represented by node calls the sub-problem represented by node .
e.g. For the recurrence
Note that not all leaves are in the last level, hence the total cost is at most
Master Theorem
Master Theorem
Consider
, can be or .
- If
for some constant , then . - If
, then . More generally, if for some integer , then . - If
for some constant and if for some constant and , then .
e.g. Consider