This Strategy Is Not New - Naming It Was the Breakthrough
Two TAs (teaching assistants) splitting a stack of exam papers already showed you this shape. Today it gets a name and a history.
1945: John von Neumann describes merge sort - split the list in
half, sort each half, merge the results (Week 6). At the time, it's
just "a clever sorting trick."
1969: Volker Strassen publishes a way to multiply two matrices
faster than the "obvious" method, by splitting each matrix into
quarters and combining the results in an unexpected way. A completely
different problem, the same divide/solve/combine shape.
1974: Aho, Hopcroft, and Ullman's The Design and Analysis of
Computer Algorithms is the first major textbook to pull this
recurring shape out of individual algorithms and teach it as its own
reusable strategy - one of a small handful of general paradigms.
Why Naming the Pattern Mattered
Merge sort, Strassen's algorithm, and the textbook that connected them.
Once the pattern had a name, computer scientists could point it at new
problems on purpose, instead of stumbling onto it by luck.
Before 1974, "divide, solve the pieces, combine" was a coincidence
two different algorithms happened to share - nobody had a name to
search for, teach, or reuse on purpose.
Naming a pattern is itself a kind of invention: it turns a one-off
trick into a checklist you can apply to a problem you've never seen,
which is exactly the shortcut this week's driving question asks for.
Key Words Today
Recurrence: an equation that defines a function's cost in terms of
its own cost on smaller inputs - what Week 4 taught you to trace.
Master theorem: a direct formula for solving recurrences of the
shape , without tracing the whole recursion tree.
Crossing subarray: in the maximum-subarray problem, a candidate
answer that starts in the left half and ends in the right half.
Watershed function: shorthand for , the quantity the
Master theorem compares against.
Divide and Conquer: Definition
Picture two TAs splitting 200 exam papers, each counting a subtotal, then adding the two together - that shape, precisely.
A divide-and-conquer algorithm solves a problem of size by: (1) Divide the problem into independent subproblems of
roughly size ; (2) Conquer each subproblem recursively, solving
it directly once it's small enough (the base case); (3) Combine the
subproblems' solutions into a solution for the original problem.
Independent is doing real work in that definition: the subproblems
must not overlap or depend on each other's answers.
Skip the combine step, or let the subproblems overlap, and it is
recursion - just not this paradigm. More on that later.
CLRS (Cormen/Leiserson/Rivest/Stein's Introduction to Algorithms) 4th ed - Ch 4, Sections 4.1 (Multiplying square matrices), 4.2 (Strassen's algorithm), 4.5 (the master method); CLRS Section 31.6 for fast exponentiation.
The General Template
1. Divide
Split the problem into smaller pieces of the same kind
›
2. Conquer
Solve each piece recursively - directly, if small enough
›
3. Combine
Merge the pieces' answers into one answer for the whole
Picture grading exams: divide the pile in two, conquer by
having each TA count their own stack, combine by adding the two
subtotals. Merge sort (Week 6) is exactly this shape, applied to sorting.
Measuring the Cost: Recurrences, Revisited
Week 4 taught you to trace these by hand. Today you get a shortcut.
Every divide-and-conquer algorithm's running time has the shape:
- how many subproblems each call makes
- the size of each subproblem ( is the shrink factor)
- the cost of the divide and combine steps themselves, outside the recursive calls
Merge sort: subproblems, (each half the size), and merging
two sorted halves costs . So .
The Master Theorem: Setup
Week 4 only previewed this intuitively. Here it is, formalized.
Given , with and , compare against the watershed function - the cost the
recursive calls alone would produce if the divide/combine steps were
free.
smaller than the watershed → the recursive calls dominate.
equal to the watershed → both contribute equally.
larger than the watershed → the divide/combine step dominates.
Three cases, one for each possibility. No tracing the whole tree required.
The Master Theorem: Three Cases
Case
Condition on
Result
1
for some (grows polynomially slower)
2
(grows at the same rate)
3
for some (grows polynomially faster), and the regularity condition holds for some constant and all large
When the Master Theorem Doesn't Apply
Three cases, but they don't cover every recurrence - and this shortcut is not a universal solver.
Not every recurrence fits one of these three cases cleanly - if f(n)
falls in the gap between cases, or case 3's regularity condition fails,
the Master theorem simply doesn't apply, and you're back to tracing the
tree by hand (Week 4), which always works even when this shortcut doesn't.
Gap example: against watershed - this is
smaller than , but not polynomially smaller by any fixed , so it fits neither Case 1 nor Case 2.
Regularity failure example: that oscillates wildly between
very small and very large values as grows can satisfy Case 3's
growth condition while still failing the regularity condition .
Master theorem · worked example 1 of 3 (simple)
Classifying Binary Search's Recurrence
The smallest case: one recursive call, no combine step at all.
GoalClassify T(n) = T(n/2) + O(1) and confirm it matches Week 7's own bound.
1
Read off a, b, f(n)
a=1 (one recursive call), b=2 (half the size), f(n)=O(1) (one comparison per call).
→
2
Watershed
n^(log₂a) = n^(log₂1) = n^0 = 1.
→
3
Match a case
f(n)=O(1)=Θ(n^0) - exactly matches the watershed. That's **Case 2**.
✓
ConclusionT(n) = Θ(n^0 · log n) = Θ(log n) - exactly what Week 7 established by direct reasoning about halving the search space.
💡
Key takeawayEven a recurrence with only one recursive call and no combine step still fits the same three-case framework.
Master theorem · worked example 2 of 3 (moderate)
Classifying Merge Sort's Recurrence
The anchor example - the same recurrence you traced informally in Week 4 and Week 6.
GoalClassify T(n) = 2T(n/2) + Θ(n) with the three-line shortcut.
1
Read off a, b, f(n)
a=2, b=2, f(n)=Θ(n) (the linear MERGE step).
→
2
Watershed
n^(log₂a) = n^(log₂2) = n^1 = n.
→
3
Match a case
f(n)=Θ(n) exactly matches the watershed n. That's **Case 2** again.
★
Three lines, not a whole tree
T(n) = Θ(n^1 · log n) = Θ(n log n) - exactly the bound Week 6 established by tracing the recursion tree by hand, now in three lines.
✓
ConclusionΘ(n log n) - confirmed by the Master theorem instead of a full tree diagram.
💡
Key takeawayWhenever f(n) exactly matches the watershed, the recursive calls and the combine step contribute equally - that's Case 2, every time.
Master theorem · worked example 3 of 3 (harder)
A Case 1 Recurrence: T(n) = 4T(n/2) + n
Same recurrence shape as the two above - a=2 doubled to a=4 changes everything.
GoalClassify T(n) = 4T(n/2) + n, and see why the outcome differs from merge sort's.
1
Read off a, b, f(n)
a=4, b=2, f(n)=n.
→
2
Watershed
n^(log₂a) = n^(log₂4) = n^2.
→
3
Match a case
f(n)=n=O(n^(2−1)) - polynomially *slower* than the watershed n^2 (ε=1). That's **Case 1**.
★
Why this differs from merge sort
Same shrink factor b=2 and same f(n)=n as merge sort's recurrence - but a=4 instead of a=2 raises the watershed above f(n), flipping the case from 2 to 1.
✓
ConclusionT(n) = Θ(n^(log₂a)) = Θ(n^2) - the recursive calls dominate, not the combine step.
💡
Key takeawayTwo recurrences that look almost identical can land in different Master theorem cases - always recompute the watershed, never guess from the shape alone.
You've Already Done Half of This
Nothing here is new - it's what you already know, now with a name and a shortcut.
Week 4 taught you to trace a recursive algorithm's cost by hand,
one level of the tree at a time.
Week 6 built merge sort - divide the list in half, recursively sort
each half, merge the sorted halves back together - without ever
calling it "divide-and-conquer."
Today: the same shape, given a name, a formal definition, and a direct
formula (the Master theorem) so you don't have to draw the tree by
hand every time.
CampusNav: The Best Energy Window Feature
Back to today's pain - now with a plan.
A student's day is logged in 10-minute slots, each scored +1
energizing or −1 draining (a break or a class you enjoy scores
positive; a stressful meeting or a rough exam block scores negative).
CampusNav wants the single longest, most valuable contiguous stretch of
the day - the run of slots whose values sum to the largest number - even
if a draining patch sits in the middle, as long as it's outweighed by
strong enough stretches on either side.
For today's trace, consecutive same-type slots are already merged into
one block: a +4 means four energizing slots in a row; a −3 means
three draining slots in a row. This is the maximum subarray problem:
find the contiguous run with the largest sum.
Max Subarray: Idea and Pseudocode
Split at the midpoint - the tricky part is the case that straddles it.
The best contiguous run is in exactly one of three places: entirely
in the left half (recurse left), entirely in the right half
(recurse right), or crossing the midpoint - starting in the left
half, ending in the right half. Neither recursive call alone can find
this last case; it needs its own linear-time scan.
FIND-CROSSING(A, low, mid, high):
best-left = -infinity, sum = 0
for i = mid downto low:
sum += A[i]
track best-left, its start index
best-right = -infinity, sum = 0
for j = mid+1 to high:
sum += A[j]
track best-right, its end index
return (start, end, best-left + best-right)
downto counts a for loop down instead of up (Week 2's reference card). The return (...) hands back three values in one tuple, unpacked the same way a caller would write (a, b, c) = FIND-CROSSING(...).
Why the Crossing Step Must Be Linear
The one design choice that keeps this algorithm fast.
Trying every straddling (start, end) pair directly would itself cost
O(n²) work at the crossing step alone - defeating the whole point of
splitting the problem in the first place. That is exactly why FIND-CROSSING instead runs outward from the midpoint exactly once in
each direction: one linear-time scan left, one linear-time scan right,
never re-checking a pair.
Max subarray · worked example 1 of 3 (simple)
Three Elements: [2, -1, 3]
The smallest case that still has a genuine crossing candidate.
GoalFind the best contiguous run in [2, -1, 3] and see whether crossing wins.
1
Split and recurse
low=0, high=2, mid=1. Left half [2,-1]: best is [2]=2. Right half [3]: best is 3 (base case).
→
2
Crossing scan
Left from mid=1: i=1, sum=-1; i=0, sum=2-1=1 → best-left=1. Right from mid+1=2: j=2, sum=3 → best-right=3.
→
3
Compare all three
Left-best=2, right-best=3, crossing=1+3=4 (the whole array). Crossing wins.
✓
ConclusionBest run is the whole array, [2, -1, 3], summing to 4 - exactly 2 + (-1) + 3.
💡
Key takeawayEven with just one negative element in the middle, the crossing case can still beat both halves alone.
Max subarray · worked example 2 of 3 (moderate)
The Full Day: [4,-3,5,-2,-1,6,-3,4,-8,5]
CampusNav's actual ten-block trace, at the top level of the recursion.
GoalFind the best energy window across the full array.
1
Split
low=0, high=9, mid=4. Left half (indices 0-4): recursive best is [4,-3,5] = 6. Right half (indices 5-9): recursive best is [6,-3,4] = 7.
→
2
Crossing, left scan
From mid=4 back to 0: sums are -1, -3, 2, -1, **3** (best, at i=0) - best-left=3.
→
3
Crossing, right scan
From mid+1=5 to 9: sums are 6, 3, **7** (best, at j=7), -1, 4 - best-right=7.
→
★
Compare all three
Left-best=6 [0,2]. Right-best=7 [5,7]. Crossing=3+7=10 [0,7]. Crossing wins by a wide margin.
✓
ConclusionCampusNav's best energy window runs [0,7], worth 10 - straight through a draining dip and out the other side.
💡
Key takeawayThe winning window wasn't visible in either half alone - only the crossing scan could find it.
Max subarray · worked example 3 of 3 (harder)
What "Recursively" Actually Means Here
The moderate trace's "left half's best is 6" wasn't inspection - it's itself a full recursive call.
GoalShow every level does the same three things, then confirm the resulting recurrence.
1
One level down
[4,-3,5,-2,-1] (the left half above) splits again at its own midpoint, checks its own left/right/crossing cases, and so on down to single-element base cases.
→
2
Every level, same three steps
Split (free), recurse twice, run one linear crossing scan - repeated at every level until the base case (a single element, trivially its own best subarray).
→
3
The recurrence
Two recursive calls on halves, plus one linear crossing scan: T(n) = 2T(n/2) + Θ(n).
★
Not a coincidence
a=2, b=2, watershed=n, f(n)=Θ(n) matches it exactly → Case 2, same as merge sort → Θ(n log n). Both algorithms halve the data and do linear work to combine.
✓
ConclusionT(n) = 2T(n/2) + Θ(n) = Θ(n log n) - a genuinely faster algorithm than checking every start/end pair, discovered by applying the paradigm, not by luck.
💡
Key takeawayEvery level of a divide-and-conquer recursion repeats the exact same three steps - that repetition is what a recurrence is counting.
Key Words Today
Fast exponentiation: computing in multiplications
by repeated squaring, instead of multiplications one at a time.
Overlapping subproblems: when recursive calls solve the same
smaller subproblem more than once - the opposite of "independent,"
and the signal for dynamic programming (Week 11), not D&C.
Regularity condition: the extra requirement Master theorem Case 3
needs before it's safe to apply.
A Second D&C Technique: Fast Exponentiation
Divide-and-conquer isn't only for arrays and matrices. It also speeds up arithmetic. (CLRS 4th ed, Section 31.6)
Computing the obvious way takes multiplications: , one at a time. Divide-and-conquer does better,
by splitting the exponent in half instead of the data:
Each step does work (one squaring, and one extra multiply if
is odd) on a problem half the size: .
Fast exponentiation · worked example 1 of 3 (simple)
Computing a⁵ by Repeated Squaring
The smallest exponent that still shows both a squaring and an extra multiply.
GoalCount real multiplications for a^5, and compare to the naive approach.
4 real squarings + 2 extra multiplies = **6 multiplications**, versus 20 for the naive approach.
★
Two exponents, one bound
13 and 21 have completely different binary patterns (1101 vs. 10101), yet both hit Θ(log n) - the bound holds regardless of which bits happen to be set in n.
✓
Conclusiona²¹: 6 multiplications by repeated squaring vs. 20 naively.
💡
Key takeawayThe halving argument never depended on which specific exponent we picked - that's what makes it a genuine Θ(log n) bound, not a lucky count.
A Second D&C Trick: Halving the Shortcut Counter
Brief - this problem gets solved properly in Week 11.
CampusNav also has a 20-step shortcut you can take 1 or 2 steps at a
time. "How many distinct ways?" was Week 4's runaway recursion-tree
example: , traced
by brute force, blowing up exponentially. That recursion is not
divide-and-conquer - its two calls touch overlapping smaller
subproblems, not independent ones. But there's a genuine D&C trick
available: halve the step number itself, the same idea fast
exponentiation uses to compute by squaring. A pair of doubling
identities jumps from straight to :
A Second D&C Trick, Continued
What the two identities buy us.
Each identity does arithmetic on two already-known values, so
halving each time gives .
ConclusionBoth checks match the direct values - the doubling identities behave exactly as claimed.
💡
Key takeawayTwo matches are strong evidence, not a proof for every k - but they show the identities jump straight to ways(2k) and ways(2k+1) without computing every value in between.
Why This Trick Is Special-Cased
A preview, not the real fix.
Halving the step number is elegant, but it only works because this
particular counting recurrence has a known closed identity to
exploit - it doesn't generalize to arbitrary overlapping-subproblem
recursions.
Week 11 solves this exact 20-step counter - and the whole family of
problems shaped like it - properly, with dynamic
programming: the same numbers, a general technique instead of a
one-off trick, and Week 4's exploding recursion tree finally fixed for good.
Common Mistakes
"It's recursive, so it's divide-and-conquer." D&C requires independent subproblems plus an explicit combine step. The
shortcut-counter recursion from Week 4 is recursive but not D&C - its
two calls overlap the same smaller subproblems, which is exactly what
dynamic programming (Week 11) is built to handle differently. A quick
test: does the recursion re-derive the same smaller answer more than
once anywhere in its call tree? If yes, it's overlapping subproblems,
not independent ones.
"The Master theorem always applies." It only classifies
recurrences shaped like where fits cleanly
into one of the three cases. If falls in the gap between cases,
or Case 3's regularity condition fails, you're back to tracing the
tree (Week 4) or need a different tool entirely - this table looks
exhaustive, but it only covers recurrences of this exact shape.
What Divide-and-Conquer Cannot Do
Divide-and-conquer works when a problem's subproblems are genuinely
independent and a combine step can stitch their answers back together -
CampusNav's energy-window finder and shortcut counter both prove it. But
divide-and-conquer assumes a problem splits cleanly into independent
left/right halves that can be solved separately and then merged - not
every problem is shaped like that. Some reward one purely local choice,
made once, instead of a full recursive split.
Next Week
Week 9 leaves what to do when recursion is overkill, and a single
local choice might already be optimal unsolved. Week 10, Greedy
Algorithms, addresses it: CampusNav's room-booking assistant, built by
always granting the request that frees up a room soonest - no recursion,
no combine step, just one correct local choice repeated.
Where This Week Lives in CLRS
This week's topic
CLRS 4th ed section
Matrix multiplication (the historical D&C example)
4.1
Strassen's algorithm
4.2
The Master method / Master theorem
4.5
Fast exponentiation (repeated squaring)
31.6
If you want to go deeper (not required this week):
CLRS Sections 4.6-4.7 prove the continuous version of the Master
theorem and cover Akra-Bazzi recurrences - a more general tool for
recurrences whose subproblems aren't all the same size, which this
week's Master theorem assumes.
Summary
Divide-and-conquer is a paradigm - divide into independent
subproblems, conquer recursively, combine - not one fixed algorithm.
The Master theorem classifies into one of
three cases by comparing to , without tracing the
whole recursion tree.
The maximum-subarray problem needs a linear-time crossing step in
addition to the two recursive halves - the combine step is where the
real design work happens.
Fast exponentiation (CLRS 31.6) is a second D&C technique this
week - splitting the exponent, not the data, for
instead of multiplications.
Not every recursive algorithm is D&C - overlapping subproblems
(Week 4's shortcut counter) need a different paradigm (dynamic
programming, Week 11).
Summary, Continued
Reading: CLRS, Chapter 4 (Divide-and-Conquer: 4.1 Matrix
Multiplication and 4.2 Strassen's Algorithm, as another
divide-and-conquer example; 4.3-4.5 the Master theorem and its
proof) and Section 31.6 (fast exponentiation). The maximum-subarray
problem used in this week's worked example is a classic
divide-and-conquer teaching example (covered in earlier CLRS
editions); its recurrence and crossing-step argument are exactly the
pattern CLRS 4.1-4.2 formalize.
Prepare: think of one everyday scheduling decision where making
the locally best choice, once, feels obviously right. Bring it to Week 10.
New: Week 9 Check - a short graded exercise on the Master
theorem, maximum subarray, and fast exponentiation, released now,
due before Week 10 begins (see materials/assignments/week09-check.html).
Thank You
SLOT 1: Title
notes: Welcome the class back from the midterm. Say: "You now know how to sort, search,
and analyze recursion. Today we ask a bigger question: is there a general strategy for
*inventing* a new algorithm, instead of starting from zero every time?"
SLOT 2: Where we are
notes: Say: "The midterm covered Weeks 1-7. Weeks 9-14 are the second half: four general
design paradigms, plus graphs. Today starts paradigm number one."
SLOT 3: Recap + open wound
Key Words Today, session 1
notes: Read each term aloud once. Say these four words are today's whole shape, formalized one slide at a time.
SLOT 4: The pain (Act 1 / MOTIVATE), zero jargon
notes: Do not say "divide and conquer," "recursion," or "Big-O" here. Let the class feel that this problem is genuinely new.
SLOT 5: Cost of not knowing
SLOT 6: Driving question
SLOT 7: Learning outcomes
SLOT 8: Origin
Key Words Today, session 2
notes: Read each term aloud. Say the recurrence toolkit from Week 4 is about to get its missing piece.
SLOT 9: Core concept
Dense worked example, master theorem, simple tier
Dense worked example, master theorem, moderate tier
Dense worked example, master theorem, harder tier
CampusNav worked example intro
Dense worked example, max subarray, simple tier
Dense worked example, max subarray, moderate tier
Dense worked example, max subarray, harder tier
Key Words Today, session 3
notes: Read each term aloud. Say Week 11 gives overlapping subproblems their own paradigm.
Dense worked example, fast exponentiation, simple tier
Dense worked example, fast exponentiation, moderate tier
Dense worked example, fast exponentiation, harder tier
Dense worked example, verifying the doubling identities