Master Theorem
Master Theorem
Master Theorem
Substitution method
Recursion tree method
The master method
Substitution method
It has been explained in Lecture 4
Few Exercises:
1. T(n) = T(n/2) + T(n/2) +O(n)
2. T(n) =2T(sqrt(n)) +lg n
3. T(n) = T(2n/3) + T(n/3) + O(n)
4. T(n) = 3T (n/4) + (n2)
Recursion tree
Recursion tree
Recursion tree
Recursion tree
Recursion tree
Compression
(nlgn) grows more slowly than (n2).
Therefore, merge sort asymptotically beats
insertion sort in the worst case.
In practice, merge sort beats insertion sort for
n> 30 or so.
Go test it out for yourself!
The master method
The master method applies to recurrences of
the form
T(n) = aT(n/b) + f(n) ,