Skip to content

Master Theorem

Course: Arrays - chapter 6

where n = size of the problem

a = number of subproblems in the recursion and a >= 1

n/b = size of each subproblem

b > 1, k >= 0 and p is a real number.

Then,

$$1. \space if \space a > b^k, then \space T(n) = θ(n^{log_ba})

\newline 2. \space if \space a = b^k \newline \space \space \space 2.1 \space if \space p > -1, T(n) = θ(n^{logba} * log^{p+1}n) \newline 2.2$$

  1. If a > ⁍, then ⁍
  2. If ⁍, then
  3. If p > -1, then ⁍
  4. If p = -1, then ⁍
  5. If p < -1, then ⁍
  6. if ⁍, then
  7. if p >= 0, then ⁍
  8.  if p < 0, then ⁍

Q - Solve for the following recursion

$$T(n) = T(n/2) + \theta(1)$$

Solution

Using master’s theorem:

a = 1, b = 2, k = 0, p = 0

⁍ and p > -1 is satisfied (Case 2.a)

So T(n) = ⁍

⁍(logn)

Q - Solve the following recursion

$$T(n) = 3T(n/2) + n^2$$

Solution

Using Master’s theorem:

a = 3, b = 2, k = 2, p = 0

So case 3.a is satisfied

⁍ = ⁍

Q - Solve the following recursion

$$T(n) = 3T(n/2) + log^2n$$

Solution

Using Master’s theorem,

a = 3, b = 2, k = 0, p = 2

Case 1 is satisfied

⁍