Lecture 23 — Greedy and Dynamic Programming

Position in the course

This is lecture 23 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.

This lecture runs as a workshop session (build-heavy; see the timing plan), not the standard four-case rhythm.

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 18, 20, 22 — sorting, brute force, recursion

Assumed fluencies:

Preparation task: Re-read the tower-steps case (lecture 22) solution; bring its recurrence table.

Detailed topic outline

Core (mandatory):

  1. greedy choice and the exchange argument
  2. counterexamples as falsification
  3. interval scheduling
  4. dynamic programming: states and transitions

Extension (optional enrichment):

  1. knapsack formulations
  2. greedy vs DP: the decision

Case sequence

CaseTitleDifficulty
cs-089The Coin ConjectureBeginner
cs-090The Meeting Room MarathonFoundational
cs-091The Tolerance LadderIntermediate
cs-131The Two-Desk CounterIntermediate
cs-143The Shelf ReplenishmentIntermediate
cs-092The Budgeted SyllabusAdvanced

Display each case full-screen from the student page (cases cs-089–cs-092); instructor pages cs-089–cs-092 under case-studies/instructor/ hold the full solutions, reveal guides, and discussion prompts. Applied additions cs-131, cs-143 extend the session as optional extra attempts or homework; they share the lecture's theme but teach an applied, real-world angle.

Timing plan (120 minutes)

Format: workshop session — deliberately not the standard case rhythm.

MinutesSegment
0–10Framing: the two patterns this workshop trains
10–45Cases 1–2 (cs-089, cs-090): two 5-minute attempts back to back, one joint discussion, two reveals
45–50Break
50–90Cases 3–4 (cs-091, cs-092): same double rhythm, harder material
90–110Deliberate-practice block: build or trace one of today's patterns end to end, instructor circulating
110–120Synthesis, exit questions, homework

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: Coin conjecture (cs-089): the greedy is run and confirmed on three inputs, then killed by one input — falsification in action.

Classroom activities

#ActivityMinutesFormat and prompt
1Counterexample lab9Greedy strategies for three problems; each team's job is one falsifying input.
2DP table relay10cs-092's table filled row by row by relay teams; errors are caught at row handoffs.
3Greedy-or-DP court6Two new problems argued both ways; the class is the jury with a decision criterion.

Board plan

Instructor explanation notes

Reading the room. Two giant ideas share a lecture by design: their contrast is the lesson. Greedy is falsified by counterexample; DP is justified by overlapping subproblems.

Running the reveal. Workshop format with extended blocks; expect fatigue — the DP relay works best right after the break.

Lecture focus. One sentence to repeat verbatim: Falsify greedy with one input; justify DP with overlap.

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. Find the falsifying input for cs-089's greedy from its instructor page; verify it by hand.
  2. Schedule cs-090's six meetings greedily by earliest-end; prove the exchange step for one swap.
  3. Fill two rows of cs-092's DP table and explain one cell's max in words.

Enrichment (optional):

Formative assessment

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

  1. What one input kills cs-089's greedy? Expected: the non-canonical coin set instance from its instructor page
  1. State the exchange argument for earliest-end scheduling. Expected: swapping a later-ending chosen meeting for an earlier-ending one never hurts
  1. What makes a DP state adequate? Expected: it captures everything the future decisions need to know

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