Case-based lecture: you attempt, we discuss, then we reveal.
cs-089, cs-090, cs-091, cs-131, cs-143, cs-092Meetings (9,10.5), (9.5,11), (11,12), (10.5,12.5). Book as many non-overlapping meetings as possible in one room.
meetings = [(9, 10.5), (9.5, 11), (11, 12), (10.5, 12.5)]
ms = sorted(meetings, key=lambda m: m[1])
taken = 0
last_end = float("-inf")
chosen = []
for s, e in ms:
if s >= last_end:
taken += 1
last_end = e
chosen.append((s, e))
print(taken, chosen)Expected: 2 meetings: (9, 10.5) and (11, 12)
Cost: O(n log n) for the sort, O(n) for the sweep.
A tolerance budget of 10 units; items cost 4, 5, 6, 7. Maximise how many items fit - then find a cost profile where 'cheapest first' fails.
costs = [4, 5, 6, 7]
budget = 10
costs.sort()
taken = spent = 0
for c in costs:
if spent + c <= budget:
taken += 1
spent += c
print(taken, spent, budget - spent)Expected: 2 items (4 + 5), leftover 1 - optimal for count, NOT for leftover (4+6 fills exactly)
Cost: O(n log n) sort dominates; the check-for-counterexample habit costs nothing and saves wrong answers.
Topics with (hours, points): (3,60), (2,50), (4,80), (1,30). Study budget 5 hours; maximise total points (each topic taken at most once).
topics = [(3, 60), (2, 50), (4, 80), (1, 30)]
budget = 5
dp = [0] * (budget + 1)
for h, p in topics:
for j in range(budget, h - 1, -1):
dp[j] = max(dp[j], dp[j - h] + p)
print(dp[budget])Expected: 110 points (topics (2,50) and (3,60))
Cost: O(items x budget) time and O(budget) space - the classic DP price, paid to buy optimality that greedy cannot guarantee here.
Greedy coin change works for one coin system and fails for another. Find the failing case, explain why, and state when greedy is safe.
**Input:** coins {1, 5, 10, 25} for 87 -> greedy 25x3+10x1+1x2 = 6 coins; system {1, 3, 4} for 6 -> greedy 4+1+1 = 3, optimal 3+3 = 2**Output:** greedy optimal for the first system; FAILS for the second - one counterexample kills the claimSolve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-089 — not embedded in this deck.
Choose the most non-overlapping meetings. Sort by end time; argue the choice with an exchange argument. Greedy with a proof-shaped justification.
**Input:** meetings [(0,3), (1,2), (3,5), (4,7), (7,9)]**Output:** max non-overlapping = 4: (1,2), (3,5), (7,9) + one of (0,3)/(4,7) variant -> verify count 4Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-090 — not embedded in this deck.
Longest increasing subsequence of exam scores. Define the DP state, transition, and read the answer; then reconstruct the sequence itself.
**Input:** scores [3, 1, 8, 2, 9, 4]**Output:** LIS = [3, 8, 9] or [1, 8, 9] or [1, 2, 4] or [3, 4]... length 3; dp[i] = longest ending at iSolve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-091 — not embedded in this deck.
A campus help desk serves students one at a time. Eight students will arrive today; their arrival minute and service duration (in minutes) are known in advance:
**Input:** the arrival/service table, the two designs**Output:** one desk: total wait 48 min, last finish 28 — two desks:total wait 3 min, last finish 18Solve for the worked instance first. Then ask what would change if onePseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-131 — not embedded in this deck.
A corner shop has 20 shelves. One assistant visits each shelf **once per day, in a fixed order**, and can restock only what fits in their cart (capacity 30 units). Each shelf sells a known number of units per day:
**Input:** per-day sales rates, cart capacity 30, cadence 1 day**Output:** a rule of the form "restock shelf X to at least 2× itsdaily rate" — shelf A safe — and the identified failure shelf undercadence 2Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-143 — not embedded in this deck.
Choose topics to study under an hour budget, maximising expected marks (weights and values). Knapsack DP; the table as the solution, not just the number.
**Input:** hours [3, 4, 2], marks [50, 70, 40], budget 6**Output:** best: topic2(4h,70) + topic3(2h,40) = 110 marks (vs topic1+3 = 90; topic1+2 over budget)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-092 — not embedded in this deck.