cs-091 — The Tolerance Ladder
| Field | Value |
|---|---|
| id | cs-091 |
| difficulty | Intermediate |
| topics | dynamic programming, states |
| lecture | lecture-23 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | loops, lists, and tracing from lectures 1-6 |
| objective | choose the technique, trace it faithfully, and defend the boundary behaviour |
| solution | held by the instructor; discussed after the attempt |
Problem
Longest increasing subsequence of exam scores. Define the DP state, transition, and read the answer; then reconstruct the sequence itself.
Your deliverable is the recurrence with base cases, the answer for the worked instance, and the memoised (or tabulated) version. 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 [3, 1, 8, 2, 9, 4]
- Output: LIS = [3, 8, 9] or [1, 8, 9] or [1, 2, 4] or [3, 4]... length 3; dp[i] = longest ending at i
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
- State: best[i] = longest increasing subsequence ENDING at i. Transition: best[i] = 1 + max(best[j] for j<i with a[j]<a[i]).
- 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: "Where does the memory go in the memoised version, and what is the trade?"
Constraints and assumptions
- Difficulty: Intermediate (loops and lists assumed).
- Topics: dynamic programming, states.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for the plan and trace; finishing the details is a bonus, defending the method is the target.
- 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.