Problem Solving — CS & DS

Lecture 32 — The Whole Toolbox: Capstone Cases

Learning objectives

Case-based lecture: you attempt, we discuss, then we reveal.

Today

The plan

Key definitions

Key definitions

Explain each in one breath; the cases will do the heavy lifting.
Worked example

The Library Robot: capstone run-through

cs-125

A robot returns books: requests (minute, shelf) pairs arrive; the robot serves shelves in increasing minute order, one per minute, and idle-waits otherwise. Compute total idle time and the busiest shelf. Full method: model, plan, solve, test, present.

requests = [(2, "A"), (3, "B"), (7, "A"), (7, "C"), (9, "B")]
requests.sort()
clock = idle = 0
tally = {}
for m, shelf in requests:
    if m > clock:
        idle += m - clock
        clock = m
    tally[shelf] = tally.get(shelf, 0) + 1
    clock += 1
busiest = sorted(tally.items(), key=lambda kv: (-kv[1], kv[0]))[0][0]
print(idle, busiest)

Expected: total idle 3 minutes; busiest shelf A (tie with B, alphabetical)

Cost: O(k log k) for the sort, O(k) service; the presentation, not the code, is the exam.

Worked example

The Open-Day Planner: capstone under time pressure

cs-126

Six talks with (start, end, room-needed or None), rooms R1 R2. Fit every talk or report the minimal set to drop. Twenty minutes, method marks for the plan.

talks = [(9, 10), (9.5, 10.5), (10, 11), (10.5, 11.5), (11, 12), (11.5, 12.5)]
talks = sorted(talks, key=lambda t: t[1])
rooms = [0.0, 0.0]
placed, dropped = [], []
for idx, (s, e) in enumerate(talks):
    r = rooms.index(min(rooms))
    if rooms[r] <= s:
        rooms[r] = e
        placed.append((s, e))
    else:
        dropped.append((s, e))
print(len(placed), len(dropped))

Expected: all 6 talks placed; nothing dropped (with these arrivals)

Cost: O(n log n) sort + O(n x rooms) placement; the marks are in the plan write-up.

Worked example

The Data Clinic: capstone synthesis

cs-127

One messy table: missing cells, a duplicated row, one impossible value, and a mixed-case category. Clean it with an audit trail, then produce ONE honest summary sentence. All semester, one page.

rows = [("Ada", "CS", 80), ("ada", "cs", 80), ("Bo", "DS", None), ("Cy", "DS", 150)]
seen, clean, log = set(), [], []
for name, cat, val in rows:
    key = (name.lower(), cat.lower(), val)
    if key in seen:
        log.append(f"duplicate {name}")
        continue
    seen.add(key)
    if val is None:
        log.append(f"missing {name}")
        continue
    if not 0 <= val <= 100:
        log.append(f"impossible {name}: {val}")
        continue
    clean.append((name.title(), cat.upper(), val))
print(clean, log)

Expected: 1 clean row; audit log: 1 duplicate, 1 missing, 1 impossible

Cost: O(n); the grade lives in what the log says, not what the loop costs.

Case attempt · lecture 32
Case cs-125 · Beginner

The Library Robot

A robot returns books to shelves minimising total walking, with a battery limit. Route planning meets knapsack-ish choice; full method: model, algorithm, tests.

⏱ 5 minutes — attempt now

Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.

Discussion

cs-125 — discuss

Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-125 — not embedded in this deck.

Case attempt · lecture 32
Case cs-126 · Foundational

The Open-Day Planner

Schedule taster talks from preferences and room limits to maximise satisfied visitors. Greedy with a tie-break rule, evaluated against a simulation of visitor happiness.

⏱ 5 minutes — attempt now

Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.

Discussion

cs-126 — discuss

Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-126 — not embedded in this deck.

Case attempt · lecture 32
Case cs-127 · Intermediate

The Data Clinic

A messy departmental dataset end-to-end: profile, clean, summarise honestly, and answer three posed questions with stated limitations.

⏱ 5 minutes — attempt now

Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.

Discussion

cs-127 — discuss

Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-127 — not embedded in this deck.

Case attempt · lecture 32
Case cs-128 · Advanced

The 20-Minute Final

Two unseen capstone problems under exam conditions, then a structured debrief mapping each step to the lecture that taught it. The course, walked backwards.

⏱ 5 minutes — attempt now

Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.

Discussion

cs-128 — discuss

Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-128 — not embedded in this deck.

Check yourself

Common misconceptions

Summary

Summary & exit question

Exit question (choose one, 60 seconds)

  1. What did the plan-first discipline buy you today?
  2. Name two cases where two techniques had to combine.
  3. What is your next technique to strengthen, and where will you practise it?
Expected answers (instructor): a defensible partial answer under a hard cap cs-125 (graphs + greedy), cs-127 (cleaning + statistics) student's own map from the retrospective
→ / space: next · ←: back · Home/End: jump · Ctrl+P → PDF