| written 6.8 years ago by |
Master Method is a direct way to get the solution. The master method works only for following type of recurrences or for recurrences that can be transformed to following type.
T(n) = aT(n/b) + f(n) where a $\gt$;= 1 and b $\gt$; 1
There are following three cases:
1. If f(n) = Θ(n c ) where c $\lt$; Log b a then T(n) = Θ(n$^{Log}$ $_{ b}$ a)
2. If f(n) = Θ(n c ) where c = Log b a then T(n) = Θ(n c Log n)
3.If f(n) = Θ(n c ) where c $\gt$; Log b a then T(n) = Θ(f(n))
How does this work?

Master method is mainly derived from recurrence tree method. If we draw recurrence tree of T(n) = aT(n/b) + f(n), we can see that the work done at root is f(n) and work done at all leaves is Θ(n$^{c}$ ) where c is Log$_{b}$ a. And the height of recurrence tree is Log$_{ b}$ n
In recurrence tree method, we calculate total work done. If the work done at leaves is polynomials more, then leaves are the dominant part, and our result becomes the work done at leaves (Case 1). If work done at leaves and root is asymptotically same, then our result becomes height multiplied by work done at any level (Case 2). If work done at root is asymptotically more, then our result becomes work done at root (Case 3).
Examples of some standard algorithms whose time complexity can be evaluated using Master Method
Merge Sort: T(n) = 2T(n/2) + Θ(n). It falls in case 2 as c is 1 and Log b a] is also 1. So the solution is Θ(n Logn)
Binary Search: T(n) = T(n/2) + Θ(1). It also falls in case 2 as c is 0 and Log$_{ b}$ a is also 0. So the solution is Θ(Logn)
Notes: 1) It is not necessary that a recurrence of the form T(n) = aT(n/b) + f(n) can be solved using Master Theorem. The given three cases have some gaps between them. For example, the recurrence T(n) = 2T(n/2) + n/Logn cannot be solved using master method.
2) Case 2 can be extended for f(n) = Θ(n$^{c}$ Log$^{k}$ n) If f(n) = Θ(n$^{c}$ Log$^{k}$ n) for some constant k $\gt$;= 0 and c = Log$_{b}$ a, then T(n) = Θ(n$^{c}$ Log$^{k+1}$ n)

and 3 others joined a min ago.