cs-094 — The Campus Walk
| Field | Value |
|---|---|
| id | cs-094 |
| difficulty | Foundational |
| topics | bfs, shortest path |
| lecture | lecture-24 |
| 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
Fewest corridors between two rooms. Breadth-first search on a small grid/campus map; levels as distances.
Your deliverable is the graph model (nodes/edges), the traversal result for the worked instance, and the unreachable-case behaviour. 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: grid campus: S at (0,0), T at (2,2); corridors right/down/up; wall at (1,1)
- Output: shortest walk 4 steps (e.g. down, right, down, right) - BFS levels are distances
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
- BFS from S; the first time you pop T, its level is the distance. Walls are just missing edges.
- The modelling choice (what is a node?) is the actual problem.
- BFS layers are distances — that is why it answers 'fewest steps'.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Re-model the same situation with different nodes: what question does the new graph answer?"
Constraints and assumptions
- Difficulty: Foundational (early-semester techniques assumed: precise statements, traces, simple loops).
- Topics: bfs, shortest path.
- 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: Re-model with the opposite edge direction and describe what the traversal gives.