Lecture 22 — Recursion and Divide-and-Conquer

Position in the course

This is lecture 22 of 32. It belongs to the course arc described in the course outline and uses the standard interactive case method: display, attempt (5 minutes), discuss, reveal, name the technique.

Learning objectives

By the end of this lecture students can do all three under time pressure, which is what the four cases exercise.

Prerequisite knowledge

Before this lecture: Lectures 06 and 21 — tracing and halving

Assumed fluencies:

Preparation task: Trace factorial(4) as a tree of calls on paper.

Detailed topic outline

Core (mandatory):

  1. recursion as self-similar subproblems
  2. base cases and the call tree
  3. recurrence relations
  4. divide and conquer: power by halving

Extension (optional enrichment):

  1. recursion to table: the DP preview
  2. when recursion clarifies and when it costs

Case sequence

CaseTitleDifficulty
cs-085The Russian DollsBeginner
cs-086Digit Sum, TwiceFoundational
cs-087Power by HalvingIntermediate
cs-088The Tower StepsExpert

Display each case full-screen from the student page (cases cs-085–cs-088); instructor pages cs-085–cs-088 under case-studies/instructor/ hold the full solutions, reveal guides, and discussion prompts.

Timing plan (120 minutes)

MinutesSegment
0–10Framing: where this fits; recall of the previous lecture
10–30Case 1 (cs-085): 5-minute attempt, then discussion and reveal
30–50Case 2 (cs-086): same rhythm
50–70Case 3 (cs-087): same rhythm, harder case
70–75Break
75–100Case 4 (cs-088): same rhythm, hardest case
100–115Synthesis: name the techniques; misconceptions check
115–120Exit questions, homework, next-lecture preview

Timing flexes with the room: if a case ignites the class, let the discussion run and compress the synthesis; if the attempts stall, harvest partial attempts rather than extending the clock.

Worked examples

Instructor demonstration to open the lecture: Tower steps (cs-088): build the call tree for n = 5, then fill the table bottom-up — recursion becomes a table before their eyes.

Classroom activities

#ActivityMinutesFormat and prompt
1Call-tree drawing7cs-086's digit-sum tree drawn and annotated with call counts.
2Recursion vs table8The tower steps (cs-088) solved both ways; the table's speed is felt.
3Base-case hunt5Three recursive definitions; teams find the input that never reaches a base case.

Board plan

Instructor explanation notes

Reading the room. Recursion is taught as trust: assume the smaller call works, solve the step, and the base case grounds it. Call trees precede code; tables follow code.

Running the reveal. The DP preview (cs-088) is planted deliberately: lecture 23's tables should feel like an old friend, not a new topic.

Lecture focus. One sentence to repeat verbatim: Trust the smaller call; ground it in the base case.

Common misconceptions

Each case's instructor page lists the specific wrong turn to expect; the reveal should address it by name.

Student practice exercises

Core:

  1. Draw the call tree for digit-sum(9876) (cs-086) and count calls.
  2. Implement power-by-halving (cs-087) and count multiplications for a^13 vs naive.
  3. Fill the tower-steps table (cs-088) for n = 1..8 bottom-up.

Enrichment (optional):

Formative assessment

Exit questions (choose one; answer on a card in 60 seconds):

  1. What grounds a recursion? Expected: a base case reachable for every input path
  1. When does a table beat the tree? Expected: when subproblems repeat — overlapping subproblems
  1. What did cs-087 buy with halving? Expected: multiplications dropped from ~13 to ~5 — logarithmic vs linear

Cards are skimmed before the next lecture; three answers become the framing. Persistent wrong answers route students to the review stations of lecture 16 or to office hours.

Homework and preparation

Learning-outcome mapping

Differentiation