CS 3343/3341
 Analysis of Algorithms 
  Recurrences   
   Master Theorem  


Introduction: Here is your text's statement of the theorem and a brief overview description:


Click picture or here for full size picture.

The paragraph at the end above describes the "Cookbook" aspect of this theorem. It amounts to a simple sequence of steps. [Illustrated here for the recurrence: T(n) = 4 T(n/2) + n2]:

  1. Determine the magic numbers a and b. [Here a = 4 and b = 2.]

  2. Calculate logb(a). [Here log2(4) = 2. In general, to calculate logb(a) = x, remember that this means bx = a. You can also use logb(a) = log10(a) / log10(b).]

  3. Focus on the function nlogb(a). [Here this is n2.]

  4. Compare the function in iii above to the function f(n), with the comparision as powers of n. We are comparing the exponents of n. [Here they are equal, both n2.]

  5. Now there are three cases:

    1. Case > : If nlogb(a) > f(n), then T(n) = Θ(nlogb(a) ). [This is not true in our example, but if f(n) were equal to n in our example, then we would have T(n) = Θ(n2).]

    2. Case = : If nlogb(a) = f(n), then T(n) = Θ(nlogb(a) log2(n)). [This is the situation in the example we are using, so T(n) = Θ(n2 log2(n)).]

    3. Case < : If nlogb(a) < f(n), then T(n) = Θ(f(n)). [This is not true in our example, but if f(n) were equal to n3 in our example, then we would have T(n) = Θ(f(n)) = Θ(n3).]

  6. [In our example above, if f(n) were equal to n2 log(n), then it might seem like Case 3 would apply, since f(n) is larger, but for case 3 to apply, f(n) must be larger as a power of n. So here the Master Method would not work at all.]

Here are some specific examples. The first three give the example in the description above, along with its two variants. The next two examples are regular matrix multiplication and Strassen's version: matrix multiplication. The two examples after that are regular integer multiplication, and the divide and conquer version: Multiply in Θ(n1.585). For the last example, where the Master Method fails, see the discussion in your text, at the bottom of page 95 and on to the top of page 96.

Recurreces, solution by Master Method, Examples
Recurrenceab logb(a)nlogb(a) f(n)CaseBehavior
T(n) = 4 T(n / 2) + n2 42log2(4) = 2 n2n2 2Θ(n2 log2(n))
T(n) = 4 T(n / 2) + n 42log2(4) = 2 n2n 1Θ(n2)
T(n) = 4 T(n / 2) + n3 42log2(4) = 2 n2n3 3Θ(n3)
T(n) = 8 T(n / 2) + Θ(n2) 82log2(8) = 3 n3n2 1Θ(n3)
T(n) = 7 T(n / 2) + Θ(n2) 72log2(7) = 2.807 n2.807n2 1Θ(n2.81)
T(n) = 4 T(n / 2) + Θ(n) 42log2(4) = 2 n2n 1Θ(n2)
T(n) = 3 T(n / 2) + Θ(n) 32log2(3) = 1.585 n1.585n 1Θ(n1.585)
T(n) = 2 T(n / 2) + n*log(n) 22log2(2) = 1 n1n*log(n) noneMaster fails


Revision date: 2012-02-18. (Please use ISO 8601, the International Standard Date and Time Notation.)