cs-092 — The Budgeted Syllabus
| Field | Value |
|---|---|
| id | cs-092 |
| difficulty | Advanced |
| topics | dynamic programming, knapsack |
| lecture | lecture-23 |
| 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
Choose topics to study under an hour budget, maximising expected marks (weights and values). Knapsack DP; the table as the solution, not just the number.
Your deliverable is the answer for the worked instance, the DP table (item by budget) with one row and one column explained, and which choices the traceback recovers. 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: hours [3, 4, 2], marks [50, 70, 40], budget 6
- Output: best: topic2(4h,70) + topic3(2h,40) = 110 marks (vs topic1+3 = 90; topic1+2 over budget)
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
- Classic knapsack: dp[h] = best marks with h hours. Fill row by row, each topic used at most once.
- Trust the recursive call: if f(smaller) is correct, the transition is all you must get right.
- A DP table is the call tree, cached.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "State f(k)'s meaning in words; is your statement precise enough to code from?"
Constraints and assumptions
- Difficulty: Advanced (functions, dictionaries, and algorithmic reasoning assumed).
- Topics: dynamic programming, knapsack.
- 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: Try the greedy rule, break it, then repair with dynamic programming.