Master Theorem for Divide and Conquer Recurrences (original) (raw)

Last Updated : 12 Jan, 2026

The Master Theorem is a tool used to solve recurrence relations that arise in the analysis of divide-and-conquer algorithms. The theorem gives asymptotic bounds on T(n) in terms of standard notations like Θ, O, and Ω. The Master Theorem provides a systematic way of solving recurrence relations of the following form

consider_the_recurrence_relation_

where:

\footnotesize\begin{aligned}&\textbf{Master Theorem — Three Cases} \\&T(n) = aT(n/b) + f(n), \text{ where } a \ge 1 \text{ and } b > 1 \\\hline \\&\textbf{Case 1:} \\&\text{If } f(n) = O(n^{\log_b a - \epsilon}) \text{ for some constant } \epsilon > 0, \text{ then:} \\&T(n) = \Theta(n^{\log_b a}) \\\\&\textbf{Case 2:} \\&\text{If } f(n) = \Theta(n^{\log_b a} \log^k n) \text{ for some constant } k \ge 0, \text{ then:} \\&T(n) = \Theta(n^{\log_b a} \log^{k+1} n) \\\\&\textbf{Case 3:} \\&\text{If } f(n) = \Omega(n^{\log_b a + \epsilon}) \text{ for some constant } \epsilon > 0, \text{ and if } \\&a f(n/b) \le c f(n) \text{ for some constant } c < 1, \text{ then:} \\&T(n) = \Theta(f(n))\end{aligned}

There are the following three cases:

The above recurrence relation accusers when an algorithm has the following type of recursive structure.

CSS `

function f(input x of size n) if (n < k) solve x directly and return else divide x into a subproblems of size n/b recursively solve each subproblem combine the results

`

In this structure:

Hence, the running time can be expressed as:

T(n) = aT(n/b) + f(n)

When Master Theorem Cannot Be Applied

The Master Theorem does not apply in the following cases:

Examples

T(n) = T(n/2) + O(1)

T(n) = Θ(logn)

**Example 2: Merge Sort

T(n) = 2 T(n/2) + O(n)

T(n) = Θ(n log ⁡n)

**Example 3

T(n) = 3T(n/2) + n2

T(n) = Θ(n2)

How does the theorem work?

The master method is mainly derived from the recurrence tree method. If we draw the recurrence tree of T(n) = aT(n/b) + f(n), we can see that the work done at the root is f(n), and work done at all leaves is O(nc) where c is Logba. And the height of the recurrence tree is Logbn

Master Theorem

In the recurrence tree method, we calculate the total work done. If the work done at leaves is polynomially 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 the same, then our result becomes height multiplied by work done at any level (Case 2). If work done at the root is asymptotically more, then our result becomes work done at the root (Case 3).

Key Points

Advanced Version of Master Theorem

Not all recurrence relations can be solved with the use of the master theorem i.e. if

The advanced version of the Master Theorem can handle recurrences with multiple terms and more complex functions.

This theorem is an advance version of master theorem that can be used to determine running time of divide and conquer algorithms if the recurrence is of the following form :-

t_n_at_n_b_nklogpn_

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. if a > bk, then T(n) = θ(nlogba)
  2. if a = bk, then
    (a) if p > -1, then T(n) = θ(nlogba logp+1n)
    (b) if p = -1, then T(n) = θ(nlogba loglogn)
    (c) if p < -1, then T(n) = θ(nlogba)
  3. if a < bk, then
    (a) if p >= 0, then T(n) = θ(nk logpn)
    (b) if p < 0, then T(n) = θ(nk)

**Example 1: T(n) = 3T(n/2) + log2n
a = 3, b = 2, k = 0, p = 2
bk = 1. So, a > bk [Case 1]
T(n) = θ(nlogba )
T(n) = θ(nlog23)

**Example 2: T(n) = 2T(n/2) + nlog2n
a = 2, b = 2, k = 1, p = 2
bk = 2. So, a = bk [Case 2.(a)]
T(n) = θ(nlogbalogp+1n )
T(n) = θ(nlog22log3n)
T(n) = θ(nlog3n)

**Example 3: T(n) = 2nT(n/2) + nn
This recurrence can't be solved using above method since function is not of form T(n) = aT(n/b) + θ(nk logpn)

**Practice Questions