QA
Senior LevelData Structures & Algorithms

How does the Master Theorem solve Divide-and-Conquer recurrences?

ā“ Interview Prompt: State the Master Theorem for T(N) = aT(N/b) + f(N) and solve recurrences for Merge Sort, Binary Search, and Strassen's algorithm.

The Master Theorem solves recurrences of the form:

$$T(N) = a \cdot T(N/b) + f(N)$$

where $a \geq 1$, $b > 1$, $f(N)$ is the work done outside recursive calls.

Three Cases (comparing $f(N)$ to $N^{\log_b a}$):

•
Case 1: $f(N) = O(N^{\log_b a - \epsilon})$ → $T(N) = \Theta(N^{\log_b a})$. (Recursive work dominates)
•
Case 2: $f(N) = \Theta(N^{\log_b a})$ → $T(N) = \Theta(N^{\log_b a} \log N)$. (Equal contribution)
•
Case 3: $f(N) = \Omega(N^{\log_b a + \epsilon})$ → $T(N) = \Theta(f(N))$. (Non-recursive work dominates)

Examples:

•
Binary Search: $T(N) = T(N/2) + O(1)$ → Case 1 → $O(\log N)$.
•
Merge Sort: $T(N) = 2T(N/2) + O(N)$ → Case 2 → $O(N \log N)$.
•
Strassen's: $T(N) = 7T(N/2) + O(N^2)$ → Case 1 → $O(N^{\log_2 7}) \approx O(N^{2.81})$.

Code Implementation Example

markdown
Master Theorem Application Examples:

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Algorithm       │ Recurrence          │ Result              │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ Binary Search   │ T(N)=T(N/2)+O(1)   │ Case 1 → O(log N)  │
│ Merge Sort      │ T(N)=2T(N/2)+O(N)  │ Case 2 → O(N log N)│
│ Quick Sort(avg) │ T(N)=2T(N/2)+O(N)  │ Case 2 → O(N log N)│
│ Strassen's      │ T(N)=7T(N/2)+O(N²) │ Case 1 → O(N^2.81) │
│ Matrix Multiply │ T(N)=8T(N/2)+O(N²) │ Case 2 → O(N³)     │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
šŸ’”Master Theorem cases applied to common divide-and-conquer algorithms.
šŸŽÆ Interview Key Takeaway

The Master Theorem is the primary tool for analysing D&C recurrences. Strassen's O(N^2.81) matrix multiply is the canonical Case 1 example beating naive O(N³).

#DSA#Master Theorem#Recurrences#Complexity Analysis#Senior
Back to all Data Structures & Algorithms Questions→

More Data Structures & Algorithms Interview Questions

Beginner LevelData Structures & Algorithms

What is the difference between an Array and a Linked List?

Beginner LevelData Structures & Algorithms

What is Big-O Notation and why is it important?

Beginner LevelData Structures & Algorithms

What are Stack and Queue data structures and where are they used?