cs-067 — Two Sorted Halves
| Field | Value |
|---|---|
| id | cs-067 |
| difficulty | Intermediate |
| topics | search, preconditions |
| lecture | lecture-17 |
| 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
A list is two sorted runs concatenated. Find the smallest element. Shows how preconditions (knowing structure) change the algorithm.
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: [7, 9, 11, 2, 4, 6] (two sorted runs); minimum is 2
- Output: 2 at the run boundary; a plain min() scan works always - the structure allows better
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
- First try: scan for the position where a[i] > a[i+1]; the next element is the minimum (or position 0).
- 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: Intermediate (loops and lists assumed).
- Topics: search, preconditions.
- 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: State the precondition that enables a faster method and quantify the gain.