cs-096 — The Epidemic Alarm
| Field | Value |
|---|---|
| id | cs-096 |
| difficulty | Advanced |
| topics | graphs, bfs, simulation |
| lecture | lecture-24 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | functions, dictionaries, and earlier algorithmic patterns |
| objective | design the algorithm, verify it on edges, and argue correctness or trade-offs |
| solution | held by the instructor; discussed after the attempt |
Problem
Rumour spreads in a social graph each hour from a set of starters; when does everyone know it? Multi-source BFS as simulation; ties to Lecture 29.
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: starters {ada}; edges 1 hour each; graph of 6 friends
- Output: time until everyone knows = max BFS level over all reachable; disconnected -> 'never' for some
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
- Multi-source BFS: put ALL starters in the queue at distance 0; answer = max distance.
- 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: Advanced (functions, dictionaries, and algorithmic reasoning assumed).
- Topics: graphs, bfs, simulation.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for a defensible plan; a complete solution may take longer and that is expected - state where you would resume.
- 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.