Master Theorem: Simplified Guide to Analyzing Algorithm Efficiency

Ayush Keshari
2 min readJul 27, 2023

--

In the ever-advancing tech world, programmers have a fondness for the brute force approach. Yet, the quest for more effective and efficient algorithms is ever-present. To analyze these algorithms, one must understand their complexities. There are two major categories for this: Non-Recurrence Functions and Recurrence Functions.

Non-Recurrence Functions are simpler as they do not involve any recursive calls to themselves. Their complexities can be analyzed using the straightforward Direct Frequency Step Count Method.

On the other hand, Recurrence Functions present a challenge. They involve recursive calls to themselves, making complexity analysis more intricate. To tackle this enigma, mathematicians and computer scientists have devised the Master Theorem, a powerful tool that allows us to analyze and compare the performance of recurrence relations.

Definition Of The Master Theorem:-

The master theorem says that if there exist four constants ‘ a ‘ , ‘ b ‘ , ‘ k ‘ and ‘ p ‘ such that a >= 1, b > 1, k >= 0 and p is any real number also f(n) a function which is non-negative for n>=0.

Also, let T(n) be defined on the non-negative integers by recurrence such that,

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

where, n/b can be floor of n/b and ceil of n/b.

Then T(n) asymptotic bounds are given by three conditions:-

  1. When f(n) should be polynomially smaller than n^(log b(a)) then,

T(n)= theta(n^(log b(a)))

  1. When f(n) is equal to the theta(n^(log b(a))) then,

T(n)= theta((n^(log b(a)))*(log n))

4. When f(n) should be polynomially larger than n^c where c>(log b(a)) also a(f(n/b))<= k(f(n)) then,

T(n)= theta(f(n))

How to use it!

The Master Theorem states that if certain conditions are met, the complexity of the recurrence relation can be determined through three cases:

CASE 1: When ‘a > b^k’, the subproblem dominates the overall problem’s complexity, and the solution is T(n) = theta(n^(log b(a))).

CASE 2: When ‘a = b^k’, the subproblem’s complexity and overall problem’s complexity are similar. This case includes three sub-cases:

A) If ‘p > -1’, then T(n) = theta(n^(log b(a)) *(log n)^(p+1))

B) If ‘p = -1’, then T(n) = theta(n^(log b(a)) * log( log n))

C) If ‘p < -1’, then T(n) = theta(n^(log b(a)))

CASE 3: When ‘a < b^k’, the subproblem’s complexity is insignificant compared to the overall problem. Two sub-cases arise here:

A) If ‘p >= 0’, then T(n) = theta(n^(k) \ (log n)^p)*

B) If ‘p < 0’, then T(n) = theta(n^k)

In conclusion, the Master Theorem stands as a guiding star for adventurers in the tech world, helping them analyze recurrence relations and steer toward efficient algorithmic solutions so, let us embrace this powerful tool and embark on our thrilling quests to unravel the complexities of the algorithms that shape the future of technology.

--

--