← 🧩 Algorithm Design: Divide & Conquer, Greedy, DP
Subtopic 1 of 6

4.1Divide and conquer

The idea

Divide and conquer splits the problem into smaller copies, solves them recursively and combines the answers.

Think of it like this: Delegating: a manager splits a report among assistants and stitches their pieces together.

Why it exists

The cost always follows from a recurrence, so this connects directly to the Master theorem.

How it works

  1. Divide into subproblems of the same kind.
  2. Conquer each recursively (stop at a small base case).
  3. Combine the results.
  4. Solve the recurrence for the total cost.

Worked example: Strassen: 7 multiplications instead of 8

T(n) = 7T(n/2) + n² gives Θ(n^log₂7) = Θ(n^2.81), better than the schoolbook n³.

Now play with it

  • →Use the Master theorem lab with the Strassen button.
  • →Compare Karatsuba (3 subproblems) with a = 4.
AlgorithmRecurrenceTime
Binary searchT(n) = T(n/2) + 1Θ(log n)
Merge sortT(n) = 2T(n/2) + nΘ(n log n)
Max and minT(n) = 2T(n/2) + 2Θ(n), 3n/2 − 2 comparisons
KaratsubaT(n) = 3T(n/2) + nΘ(n^1.585)
StrassenT(n) = 7T(n/2) + n²Θ(n^2.81)
Closest pair of pointsT(n) = 2T(n/2) + nΘ(n log n)
Fast power xⁿT(n) = T(n/2) + 1Θ(log n) multiplications

T(n) = a · T(n / b) + Θ( nk · logp n )

log_b a2.8074
Compare with klog_b a > k
Master theoremCase 1
AnswerT(n) = Θ(n^2.807)

log_b a = 2.807 > k = 2: the leaves dominate (there are n^2.807 of them)

levelsubproblems a^isize n / b^i (n = 1024)work at the level
01102410,48,576
1751218,35,008
24925632,11,264
334312856,19,712
424016498,34,496
516807321,72,10,368

Level work shrinking down the table: root dominates (Case 3). Growing: leaves dominate (Case 1). Staying the same: Case 2, multiply by the number of levels.

Check yourself

Finding both the maximum and minimum by divide and conquer takes

Remember: D&C cost = recurrence; know Strassen n^2.81 and Karatsuba n^1.585.
Exam notes (the dense version)

Split into subproblems, solve recursively, combine. Cost comes from the recurrence T(n) = aT(n/b) + f(n). Examples: merge sort, quick sort, binary search, max and min in 3n/2 − 2 comparisons, Strassen (7 multiplications, Θ(n^2.81)), Karatsuba (3 multiplications, Θ(n^1.585)), closest pair in Θ(n log n), fast exponentiation in O(log n) multiplications.

Previous year questions: Algorithm Design: Divide & Conquer, Greedy, DP (7)

PYQs are grouped by topic, so this is the full set for Algorithm Design: Divide & Conquer, Greedy, DP; try the ones that match this subtopic. Open all 7 on the topic page.