Introduction

The Master Theorem is a powerful tool for analyzing the time complexity of divide-and-conquer algorithms. It helps us solve recurrences of the form:

where:

  • is the size of the problem,
  • is the number of subproblems,
  • is the factor by which the problem size is divided,
  • is the cost of dividing the problem and combining the results from the subproblems.

The Master Theorem provides a direct method to determine the asymptotic behavior of recurrences based on the relationship between , , and the function .

The Three Cases of the Master Theorem

Case 1:

If , then the time complexity is dominated by the recursive calls, and the solution is given by:

Example 1:

Consider the recurrence:

Here, , , and . We calculate :

Since and , we fall into Case 1 because . Therefore, the time complexity is:

Case 2:

If , the behavior depends on the function .

Case 2.1: If

If is asymptotically larger than (i.e., with ), then the complexity is determined by , and the solution is:

Example 2:

Consider the recurrence:

Here, , , and . We calculate :

Since and , we fall into Case 2.1 because grows faster than . Therefore, the time complexity is:

Case 2.2: If

If is exactly , then we check if is polynomially bounded. In this case, the solution is:

Example 3:

Consider the recurrence:

Here, , , and . We calculate :

Since and , we fall into Case 2.2. The solution is:

Case 2.3: If

If grows slower than , then the time complexity is determined by the recursive calls:

Case 3:

If , the time complexity is dominated by , and the solution is:

Example 4:

Consider the recurrence:

Here, , , and . We calculate :

Since and , we fall into Case 3 because dominates the recursive term. Therefore, the time complexity is:

Case 3.1: If

If is polynomially bounded, then the time complexity is dominated by , and the solution is:

Case 3.2: If

If grows slower than , then the solution is dominated by the recursive calls:

Summary of Master Theorem Cases

  1. Case 1: If , then .
  2. Case 2: If :
    • Case 2.1: If with , then .
    • Case 2.2: If , then .
    • Case 2.3: If , then .
  3. Case 3: If :
    • Case 3.1: If with , then .
    • Case 3.2: If , then .