cs-066 — The Course Finder
| Field | Value |
|---|---|
| id | cs-066 |
| difficulty | Foundational |
| topics | search, predicates |
| lecture | lecture-17 |
| 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
Find all courses taught in a room with capacity at least X and free on Tuesdays. Filtering as a search with a compound predicate.
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: courses [(CS1, room 40, cap 30, Tue), (DS1, room 12, cap 60, Wed), (AI, room 41, cap 45, Tue)], cap >= 40, free Tue
- Output: [DS1? no - Wed] -> matches: AI only (room cap 45, Tue); DS1 has cap but wrong day
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
- A compound predicate: capacity AND day. Filter = search that returns ALL matches.
- 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: "If this scan ran 10,000 times a day, what would you precompute?"
Constraints and assumptions
- Difficulty: Foundational (early-semester techniques assumed: precise statements, traces, simple loops).
- Topics: search, predicates.
- 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: State the precondition that enables a faster method and quantify the gain.