cs-118 — The Shift Schedule
| Field | Value |
|---|---|
| id | cs-118 |
| difficulty | Foundational |
| topics | optimization, constraints |
| lecture | lecture-30 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | lectures 1-2 (problem framing, precise pseudocode) |
| objective | recognise the pattern, translate it into precise steps, and trace it correctly |
| solution | held by the instructor; discussed after the attempt |
Problem
Cover a 7-day rota with staff availability rules. Formulate; then solve a small instance by reasoning and a bigger one by search.
Your deliverable is the enumerated answer, the space count, and the pruning rule with its measured effect. 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: 7 days, each day needs 2 staff; ada/bo/cy/dee available on subsets; max 4 days each
- Output: a feasible rota or proof none exists (try greedy by most-constrained day first)
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
- Cover the HARDEST days first (fewest available staff); if a day has zero candidates, report impossible immediately.
- Brute force is a legitimate algorithm when the space is honest about its size.
- Pruning is not cheating; it is arithmetic applied early.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Double the input size: is this still acceptable? Show the arithmetic."
Constraints and assumptions
- Difficulty: Foundational (early-semester techniques assumed: precise statements, traces, simple loops).
- Topics: optimization, constraints.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes; naming the pattern and stating the assumption is already a pass, completing the calculation is the stretch.
- 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: Reformulate with a different objective and describe how the optimum moves.