Case-based lecture: you attempt, we discuss, then we reveal.
cs-105, cs-106, cs-107, cs-140, cs-108Bookings with issues: '9:00-10:00' (fine), ' 10:30 - 11:30 ' (padded), '24:00-25:00' (invalid), '9:00-9:00' (empty). Write rules, apply them, report what was dropped and why.
raw = ["9:00-10:00", " 10:30 - 11:30 ", "24:00-25:00", "9:00-9:00"]
kept, dropped = [], []
for r in raw:
norm = " ".join(r.split()).replace(" ", "")
s, e = norm.split("-")
sh, sm = map(int, s.split(":"))
eh, em = map(int, e.split(":"))
start, end = sh * 60 + sm, eh * 60 + em
if not (0 <= start < end < 24 * 60):
dropped.append((r, "invalid range"))
else:
kept.append(f"{start:04d}-{end:04d}")
print(kept)
print(dropped)Expected: kept: 9:00-10:00 and 10:30-11:30 (normalised); dropped: the invalid and empty ranges
Cost: O(n) rows, each parsed in constant time.
Scores 78, 92, 850, 65, 88, -5. Flag impossible values; then discuss what you can and cannot conclude about suspicious-but-possible ones (e.g. 92 when the class mean is 40).
scores = [78, 92, 850, 65, 88, -5]
valid = [s for s in scores if 0 <= s <= 100]
mean = sum(valid) / len(valid)
var = sum((s - mean) ** 2 for s in valid) / len(valid)
sd = var ** 0.5
review = [s for s in valid if abs(s - mean) / sd > 2]
print(valid, mean, review)Expected: hard-dropped: 850 and -5; statistical review: none after cleaning
Cost: O(n); the guard against sd = 0 is where most student implementations break.
Hourly readings 12.0, 11.5, None, None, 13.0, 12.5. Choose a policy (drop rows, fill zero, carry forward, fill mean), apply it, and state how the choice changes the story.
readings = [12.0, 11.5, None, None, 13.0, 12.5]
present = [r for r in readings if r is not None]
drop_mean = sum(present) / len(present)
zero_fill = [r if r is not None else 0 for r in readings]
fwd = []
last = present[0]
for r in readings:
if r is not None:
last = r
fwd.append(last)
mean_fill = [r if r is not None else drop_mean for r in readings]
print(len(present), round(drop_mean, 2))
print(round(sum(zero_fill) / len(zero_fill), 2), round(sum(fwd) / len(fwd), 2), round(sum(mean_fill) / len(mean_fill), 2))Expected: drop: mean 12.25 (n=4); zero: 8.17; forward: 12.33; mean: 12.25
Cost: O(n) per policy; the cost is in the argument, not the loop.
Booking rows with missing rooms, end-before-start times, and double bookings. Define rules, count violations, decide repairs vs flags.
**Input:** rows: (room=NULL, 9-10), (B12, 10-9 end<start), (B12, 13-14) twice (double), (B14, 9-10)**Output:** 3 violations: missing room, inverted time, duplicate booking; repairs flagged not silentSolve 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-105 — not embedded in this deck.
Scores like 105, -3, 'eighty'. Categorise defects, choose a policy per category (fix, flag, drop), and defend each choice.
**Input:** scores: 105, -3, 'eighty', 84, 92**Output:** policies: 105 -> flag (over 100, maybe bonus); -3 -> correct to missing (impossible); 'eighty' -> parse to 80 (known map); else keepSolve 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-106 — not embedded in this deck.
Same student appears with name variants and id typos. Design a matching rule with a manual-review queue; measure how much the rule catches vs leaves.
**Input:** "Ada Lovelace" / "ada lovelace" / "A. Lovelace" / id "S2023-0471" vs "s2023-0471 "**Output:** match rule: lowercase+strip id first (exact); name fuzzy (initials + surname); manual queue for the restSolve 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-107 — not embedded in this deck.
Two campus bookshops, each with a coffee bar. Per-shop revenue per customer:
**Input:** the per-bar revenue table and the customer-mix table**Output:** North blended 6.67 vs South blended 13.50 — yet Northleads *within* both bars — plus the explanation and the fair comparisonSolve 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-140 — not embedded in this deck.
Temperature sensor with gaps and spikes. Distinguish dropout vs anomaly, impute or flag, and show how each choice changes a downstream average.
**Input:** temps: [12, 12.5, 13, None, 47, 12.8, None, 13]**Output:** None = dropout (impute or flag, do NOT average over silently); 47 = spike (anomaly vs real heatwave - policy needed)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-108 — not embedded in this deck.