cs-060 — The Birthday Question
| Field | Value |
|---|---|
| id | cs-060 |
| difficulty | Advanced |
| topics | probability, complement |
| lecture | lecture-15 |
| 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
How many students until two likely share a birthday? Derive the complement product, compute thresholds, and confirm by simulation. The classic that teaches complement thinking.
Your deliverable is the count (or probability) with the sample space stated, the case analysis, and a brute-force check for a small instance. 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: n people, 365 equally likely birthdays (ignore leap days)
- Output: P(no shared) = 365/365 x 364/365 x ... ; n=23 gives P(shared) ~ 50.7%
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
- No shared birthday: multiply falling terms (365-i)/365. Find the first n where 1 - product exceeds 0.5.
- 'How many total, how many favourable' is the whole skeleton of probability.
- Complements turn hairy unions into one subtraction.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Where exactly did the wrong counts double-count — point at the pair."
Constraints and assumptions
- Difficulty: Advanced (functions, dictionaries, and algorithmic reasoning assumed).
- Topics: probability, complement.
- 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-derive the count with a different method and reconcile the answers.