cs-048 — The Regression Zoo
| Field | Value |
|---|---|
| id | cs-048 |
| difficulty | Advanced |
| topics | debugging, regression |
| lecture | lecture-12 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | functions, dictionaries, and earlier algorithmic patterns |
| objective | design the algorithm, verify it on edges, and argue correctness or trade-offs |
| solution | held by the instructor; discussed after the attempt |
Problem
Three small programs, each with a distinct classic defect class (scope, mutation, boundary). Localise all three under a time budget, then rank difficulty.
Your deliverable is the minimal failing input, the ranked hypotheses, the located mechanism, the minimal fix, and a regression test. If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.
Examples
- Input: three snippets: (a) counter defined outside a function, (b) shared default list, (c) range(len(xs)) deletion loop
- Output: (a) scope defect; (b) persistent-state defect; (c) skip-after-remove defect
Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.
What to notice
- One pass per snippet: reproduce, hypothesise, localise. Budget: 6 minutes each, in that order.
- A bug is a claim about your mental model; the failing input is the experiment.
- The fix should be smaller than the explanation of the bug.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Which hypothesis did you rank first, and what evidence moved it down the list?"
Constraints and assumptions
- Difficulty: Advanced (functions, dictionaries, and algorithmic reasoning assumed).
- Topics: debugging, regression.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for a defensible plan; a complete solution may take longer and that is expected - state where you would resume.
- Optional stretch (not required): describe an alternative approach and say when it beats the obvious one.
Hints and extension
- First nudge: identify the pattern the worked instance uses before computing anything.
- If stuck after three minutes, write the input/output line you expect and trace the smallest example by hand.
- After the reveal, attempt the extension below before the next lecture.
- Extension challenge: Write the regression test that would have caught the defect earliest.