cs-093 — The Friend Circle
| Field | Value |
|---|---|
| id | cs-093 |
| difficulty | Beginner |
| topics | graphs, modeling |
| lecture | lecture-24 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | none |
| objective | state inputs, outputs, and assumptions, then solve a small instance by hand |
| solution | held by the instructor; discussed after the attempt |
Problem
Model friendships as a graph; find the size of someone's circle of direct and indirect friends. Modelling first, traversal second.
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: friends: ada-bo, bo-cy, cy-dee, dee-ada, bo-dee (5 edges among 4); ego network of ada
- Output: ada's circle: everyone (size 4) - connected graph; in general: BFS from the person
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
- Nodes = people, edges = friendship. 'Indirect friends' = reachable set = BFS.
- 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: "Where does the algorithm report 'unreachable', and what should the user see?"
Constraints and assumptions
- Difficulty: Beginner (no prior experience assumed).
- Topics: graphs, modeling.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for a first attempt; partial answers with clear reasoning are worth more than silent struggling.
- 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.