Learn Master’s Theorem to analyze divide and conquer algorithms. Understand recurrence relations, all three cases, solved examples, and time complexity.

Master’s Theorem

Master’s Theorem is an important method used to analyze the time complexity of recursive algorithms that follow the Divide and Conquer approach.

When a problem of size n is divided into smaller subproblems and solved recursively, the following recurrence relation is formed.

Standard Recurrence Form

It applies to recurrences of the form:

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

Where:

  • n → size of the problem
  • a → number of subproblems
  • n/b → size of each subproblem
  • f(n) → cost of dividing the problem and combining the results

Basic Conditions of Master Theorem

  • a≥1
  • b>1
  • f(n) must be a polynomial function, i.e.,

f(n)=Θ(nd)

Steps to Apply Master Theorem

  1. Identify a, b, and f(n)
  2. Write f(n)=Θ(nd)
  3. Compare a with bd
  4. Apply the appropriate case

Three Cases of Master Theorem

Case 1: a<bd

T(n)=Θ(nd)

Meaning:
The divide + combine cost dominates the recurrence.

Example:

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

  • a = 3
  • b = 2
  • f(n) = n2 ⇒ d = 2
  • bd = 22 = 4
  • 3 < 4 ⇒ Case 1

Final Answer:

T(n)=Θ(n2)

Case 2: a=bd

T(n)=Θ(ndlog⁡n)

Meaning:
Same amount of work is done at each level of recursion.

Example:

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

  • a = 2
  • b = 2
  • d = 1
  • bd =21 =2
  • a = bdCase 2

Final Answer:

T(n)=Θ(n log n)

Case 3: a>bd

T(n)=Θ(nlogba)

Meaning:
The recursive calls dominate the total cost.

(Regularity condition is assumed in exams)

Example:

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

Step-by-step:

  • a = 4
  • b = 2
  • f(n) = n ⇒ d = 1
  • bd = 21 = 2
  • 4 > 2 ⇒ Case 3

Log ba=log 24=2

Final Answer:

T(n)=Θ(n2)

Summary:

Comparison Final Answer
a<bd Θ(nd)
a=bd Θ (nd log n)
a>bd Θ(n log ba)

When Master Theorem Cannot Be Used

  • Recurrence is not in the form aT(n/b)+f(n)
  • f(n) is not polynomial
  • a or b are not constants
  • Unequal subproblem sizes

Some More: 

Leave a Reply

Your email address will not be published. Required fields are marked *