Case-based lecture: you attempt, we discuss, then we reveal.
cs-097, cs-098, cs-099, cs-139, cs-100Log lines like '0812 ada lunch 6.50', '0815 bo snack 2.00', '0809 ada lunch 4.00'. Build per-person totals and the busiest item - decide your cleaning rules first.
lines = ["0812 ada lunch 6.50", "0815 bo snack 2.00", "0809 ada lunch 4.00"]
totals, items = {}, {}
for ln in lines:
_t, person, item, amt = ln.split()
totals[person] = totals.get(person, 0.0) + float(amt)
items[item] = items.get(item, 0) + 1
busiest = sorted(items.items(), key=lambda kv: (-kv[1], kv[0]))[0][0]
print(round(totals["ada"], 2), busiest)Expected: ada total 10.50; busiest item 'lunch' (2 visits)
Cost: O(n) for n log lines; the ranking is O(u log u) over distinct items.
(cohort, minutes) pairs: (A, 120), (B, 90), (A, 180), (B, 110), (A, 60). Compare mean screen time per cohort - and state what the comparison cannot tell you.
rows = [("A", 120), ("B", 90), ("A", 180), ("B", 110), ("A", 60)]
groups = {}
for c, m in rows:
groups.setdefault(c, []).append(m)
for c in sorted(groups):
v = groups[c]
print(c, len(v), sum(v) / len(v))Expected: A: mean 120 (n=3); B: mean 100 (n=2)
Cost: O(n) grouping, O(g) reporting - trivial cost, the care is free but must be spent.
Cohorts: A: 40 stayed, 10 left; B: 25 stayed, 25 left. Which cohort has the worse churn rate, and what exactly does the percentage measure?
cohorts = {"A": (40, 10), "B": (25, 25)}
for c, (stayed, left) in sorted(cohorts.items()):
total = stayed + left
print(c, f"{left / total:.0%}", total)Expected: A 20% churn, B 50% churn (denominator: cohort members)
Cost: O(1) per cohort; the intellectual work is in the denominator, not the arithmetic.
From a queue-length log, answer: busiest hour, average wait proxy, quietest day. Framing questions before computing.
**Input:** queue lengths by hour: 11:00->8, 12:00->22, 13:00->25, 14:00->6; week total 950 served**Output:** busiest hour 13:00; 'average wait proxy' must be defined (e.g. queue/time) before computing; quietest day statedSolve 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-097 — not embedded in this deck.
Compare app usage across three student cohorts with counts, shares, and a distribution sketch. Choosing summaries that answer the actual question.
**Input:** cohort A app minutes [120, 90, 150]; cohort B [60, 45, 75]; cohort C [200, 180, 210, 190]**Output:** A mean 120, B mean 60, C mean 195; shares of total usage differ from headcount sharesSolve 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-098 — not embedded in this deck.
Monthly subscriber counts in and out. Define churn rate precisely (what's the base?), compute, and explain a month that 'looks bad but isn't'.
**Input:** jan: 1000 start, 50 join, 40 leave, end 1010; feb: 1010 start, 60 leave**Output:** jan churn 40/1000 = 4.0% (base = starting subscribers); feb 60/1010 ~ 5.9% - define the base firstSolve 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-099 — not embedded in this deck.
The library reports: *"Weekday visits fell 20% the week after the deadline-week survey."* Two staff proposals:
**Input:** the two weeks' visit counts and the holiday window**Output:** totals 2600 vs 970 (−63%) — per open day 520 vs 485(−6.7%) — verdict + policy ruleSolve 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-139 — not embedded in this deck.
A survey over-represents one hall of residence. Show how naive averages mislead, then reweight (or segment) to a fairer summary.
**Input:** hall weights: north 500 students sampled 200, south 300 sampled 50, east 200 sampled 50; satisfaction yes-rates 0.6, 0.5, 0.7**Output:** naive mean 0.6; weighted (by population) = (500*.6 + 300*.5 + 200*.7)/1000 = 0.59; segment-wise reporting also validSolve 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-100 — not embedded in this deck.