cs-069 — Rank the Leaderboard
| Field | Value |
|---|---|
| id | cs-069 |
| difficulty | Beginner |
| topics | sorting, keys |
| lecture | lecture-18 |
| 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
Sort players by score, then by name for ties. Stable sorting and composite keys; ties as a first-class concern.
Your deliverable is the answer for the worked instance, the precondition stated, and the not-found behaviour demonstrated. 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: scores [(bo,90), (ada,95), (cy,90), (dee,88)]
- Output: sorted: ada 95, bo 90, cy 90, dee 88 (ties alphabetical: bo before cy - stable multi-key)
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
- Key tuple (-score, name): descending on score, ascending on name, in one sort.
- Sorted data is not just faster — it enables different algorithms.
- A scan is only as good as its stated precondition.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Which boundary test would you keep if you could keep only one?"
Constraints and assumptions
- Difficulty: Beginner (no prior experience assumed).
- Topics: sorting, keys.
- 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: Add a stable tie-break rule and show a case where it matters.