cs-050 — Course Rosters
| Field | Value |
|---|---|
| id | cs-050 |
| difficulty | Foundational |
| topics | sets, operations |
| lecture | lecture-13 |
| 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
Given two course rosters, output students in both, either, and only one. Set operations as direct vocabulary.
Your deliverable is the mapping/set answers for the worked instance, the key choice justified, and the tie-break rule stated. 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: CS = {ada, bo, cy}; DS = {bo, dee, ada}
- Output: both: {ada, bo}; either: {ada, bo, cy, dee}; only CS: {cy}; only DS: {dee}
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
- Translate the English ('both', 'either', 'only') into set operators before coding.
- A dictionary turns 'search for the item' into 'look it up' — that is the whole win.
- Sets answer yes/no questions; dictionaries answer how-many questions.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "What breaks if two different real-world things map to the same key — and how would you detect it?"
Constraints and assumptions
- Difficulty: Foundational (early-semester techniques assumed: precise statements, traces, simple loops).
- Topics: sets, operations.
- 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: Invert the lookup (value to keys) and state when collisions appear.