The Master Theorem is a tool that helps determine the time complexity of recurrence relation arising from divide-and-conquer algorithms. It was formulated by computer scientist Jon Bentley, and popularized by Thomas Cormen, Charles Leiserson, Ronald Rivest, and Clifford Stein in Introduction to Algorithms.
This blog post explores the Master Theorem, its components, and how it can be applied to analyze the efficiency of algorithms.
This post is my best effort. It includes notes I used to study for a challenging class. There might be mistakes in the math! If you spot an error, please let me know. I love writing these posts and want them to be the best possible! :)
🌸👋🏻 Join 10,000+ followers! Let’s take this to your inbox. You’ll receive occasional emails about whatever’s on my mind—offensive security, open source, academics, boats, software freedom, you get the idea.
Divide-and-conquer algorithms
Before discussing the Master Theorem, let’s briefly revisit divide-and-conquer algorithms.
Divide-and-conquer algorithms solve problems by breaking them into smaller, more manageable subproblems, solving each subproblem independently, and then combining the solutions to obtain the final result.
Well-known algorithms like merge sort, quicksort, and binary search are prime examples of divide-and-conquer strategies.
Read more: Recursion: Algorithmic Paradigms, Complexities, and Pitfalls

Merge sort example
Recursive
Consider sorting an array using the merge sort algorithm (video). Each recursive call divides the array into two halves, sorts each half separately, and then merges them back together. This recursive decomposition captures the breaking down of a larger problem into smaller, more manageable subproblems.
This merge sort example demonstrates the divide and conquer paradigm by recursively dividing an array into smaller halves, independently sorting each subarray, and then merging them back together to achieve a sorted result.
However, there are multiple ways to approach this merge sort problem using divide-and-conquer.
🌸👋🏻 Join 10,000+ followers! Let’s take this to your inbox. You’ll receive occasional emails about whatever’s on my mind—offensive security, open source, academics, boats, software freedom, you get the idea.
Iterative
The divide-and-conquer paradigm does not always involve recursion; alternative strategies, such as iteration or dynamic programming, can be employed to solve subproblems and combine solutions in a non-recursive manner.
An example of the divide-and-conquer paradigm without recursion is the iterative approach to merge sort.
In a typical divide-and-conquer fashion, the array is divided into smaller subarrays until each subarray contains only one element. However, instead of using recursive calls to merge the subarrays, an iterative approach employs a loop to repeatedly merge adjacent pairs of subarrays until the entire array is sorted. This illustrates that divide-and-conquer can be implemented without relying on recursive function calls.
Components and formulation
The Master Theorem is a tool that helps determine the time complexity of recurrence relation arising from divide-and-conquer algorithms. Say a recurrence relation takes the form:
The Master Theorem provides a way to solve this recurrence relation and determine the asymptotic behavior of .
Here, represents the time complexity of the algorithm for a problem of size
,
is the number of subproblems,
is the factor by which the problem size is reduced, and
is the cost of dividing the problem and combining the results.
🌸👋🏻 Join 10,000+ followers! Let’s take this to your inbox. You’ll receive occasional emails about whatever’s on my mind—offensive security, open source, academics, boats, software freedom, you get the idea.
More math-y breakdown
where:
is the number of subproblems in the recursion.
is the factor by which the problem size is reduced in each recursive call.
is the cost of dividing the problem and combining the results.
Master Theorem cases
The Master Theorem has three cases, each corresponding to a different relationship between ,
, and
. Let’s explore each case.
Read more: Recurrence Relations: Measuring Efficiency and Optimization
Case 1
is
, where
In this case, the recursive part is the dominant factor contributing to the time complexity.
The overall time complexity is:
Math-y version
Example
In this example, ,
, and
.
The recurrence relation falls under Case 1 because is
where
.
🌸👋🏻 Join 10,000+ followers! Let’s take this to your inbox. You’ll receive occasional emails about whatever’s on my mind—offensive security, open source, academics, boats, software freedom, you get the idea.
Case 2
is
,
where
Here, the recursive part and the cost of dividing and combining contribute equally to the time complexity.
The overall time complexity is:
Math-y version
Example
Here, ,
, and
.
The recurrence relation falls under Case 2 because is:
.
Case 3
is
, where
, and
for some
and sufficiently large
In this case, the cost of dividing and combining dominates the recursive part.
The overall time complexity is .
Math-y version
and
🌸👋🏻 Join 10,000+ followers! Let’s take this to your inbox. You’ll receive occasional emails about whatever’s on my mind—offensive security, open source, academics, boats, software freedom, you get the idea.
Example
In this example, ,
, and
.
The recurrence relation falls under Case 3 because is
where
.
Additionally:
for .
Application of the Master Theorem
Now, let’s illustrate the application of the Master Theorem with a classic example using merge sort. In merge sort, ,
, and
.
Thus, we can see that it falls under Case 2, resulting in a time complexity of .
Conclusion
In conclusion, the Master Theorem helps analyze the time complexity of divide-and-conquer algorithms. By breaking down the components and formulations of the theorem, including its three distinct cases, engineers can grasp its applicability to algorithms.
If you enjoyed this post on master theorem, consider reading Algorithm Development and Analysis.


You must be logged in to post a comment.