Problem Solving — CS & DS

Lecture 01 — Thinking in Problems

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 coffee card, modelled honestly

cs-001

A cafe card gives every 10th drink free (buy 9, the 10th costs nothing). Price 3.50 per paid drink; the student wants 22 drinks this month. What do they pay?

Expected: (20, 2, 70.0)

Cost: O(wanted) time, O(1) space; a closed form (paid = wanted - wanted // 10) exists and is worth deriving as a check.

Worked example

The elevator: movement vs stops

cs-002

An elevator serves requests in press order: [3, 7, 3, 1, 5]. 3 s per floor moved, 6 s per stop (including the first). Total time?

Expected: 72

Cost: O(n) time for n requests; the *optimisation* of ordering is a different (harder) problem, previewed in Block III.

Worked example

Which vending machine? Writing the rules

cs-003

Machine A sells at 2.00, exact coins only. Machine B sells at 2.30 and gives change. The student holds specific coins. Write decision rules covering exact match, overpay possible, overpay impossible, and B sold out.

Expected: machine B / machine A / no purchase (per the three traces)

Cost: Constant time; the difficulty is specification completeness, not cost.

Worked example

The library fine, one ambiguity at a time

cs-004

Fines: 0.50/day for days 1-7, 1.00/day for days 8-30, cap 10.00. Returned on day 5, day 12, day 40 - and on the due date itself?

wanted = 22
price = 3.50
paid = wanted - wanted // 10
free = wanted // 10
print(paid, free, paid * price)

Expected: 2.50; 8.50 (our reading); 10.00; due-date return 0.00

Cost: Constant time. The pedagogical content is the two contested readings, not the arithmetic.

Case attempt · lecture 01
Case cs-001 · Beginner

The Coffee Card

A cafe loyalty card: buy 9 drinks, get 1 free. Given the price of a drink and how many drinks a student wants over a month, how much will they actually pay? Must decide what happens when a free drink is 'earned' mid-month.

⏱ 5 minutes — attempt now

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

Discussion

cs-001 — discuss

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

Case attempt · lecture 01
Case cs-002 · Foundational

The Elevator Debate

An office elevator stops at every requested floor in the order buttons were pressed. Decide the total travel time for a list of floor requests, then debate a better ordering policy.

⏱ 5 minutes — attempt now

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

Discussion

cs-002 — discuss

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

Case attempt · lecture 01
Case cs-003 · Intermediate

Two Vending Machines

Two machines sell the same drink for different prices; one accepts exact coins only, the other gives change. Write precise rules for which machine a student should use given the coins they hold.

⏱ 5 minutes — attempt now

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

Discussion

cs-003 — discuss

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

Case attempt · lecture 01
Case cs-004 · Expert

The Library Fine Formula

A library charges fines with a tiered rule (per day, capped, and waived under conditions). Turn a vague policy into an exact formula, including what happens on the return day itself.

⏱ 5 minutes — attempt now

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

Discussion

cs-004 — discuss

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

Check yourself

Common misconceptions

Summary

Summary & exit question

Exit question (choose one, 60 seconds)

  1. State the four questions you must answer before attempting any case.
  2. Give one example of two defensible readings of the same rule.
  3. Why is the five-minute attempt not wasted time?
Expected answers (instructor): inputs, outputs, constraints, assumptions (edge cases named from them) e.g. 'every 6th drink free' — counting only paid drinks vs all drinks it generates the class's own attempts, making the reveal answer a question already asked
→ / space: next · ←: back · Home/End: jump · Ctrl+P → PDF