Recurrences, Master Theorem¶
Input Size¶
The input size describes the amount of space required to describe or set up the problem. It is proportional to the amount of bits needed to store the input. The input size is the only parameter that is needed to predict Time / Space Complexity for deterministic algorithms.
Divide and Conquer¶
Divide and Conquer algorithms come in three steps
- Divide the problem into smaller (typically disjoint) subproblems
- Assume that you have already solved these subproblems below a certain layer
- With this help from the recursion fairy, combine these solutions to get the solution of the current layer
Recurrence¶
A recurrence describes the runtime of an input size of \(n\) in terms of the same algorithm applied to smaller input sizes, and some additional overhead (the combine step).
Example: for Karatsuba multiplication
\(T(1)\) describes the base case of the algorithm
Master Theorem¶
Define the recurrence as
The master theorem gives a quick way to solve simple recurrences like this
Loose Proof¶
The number of levels in the recursion tree - \(\log_b n\)
The number of subproblems at level \(j\) - \(a^j\)
The subproblem size at level \(j\) - \(n/b^j\)
Combine Phase at level \(j\) :
So the total work is
This is a geometric progression. If \(a=b^d\) , the sum evaluates to \(O(n^d \log(n))\)
If \(a < b^d\), this can be totalled as an infinite sum.
If \(a>b^d\), we can't do the same because the ratio is > 1