Pick the fix
The list is [4, 5, 6, 7, 0, 1, 2]. At the first step mid holds 7 and the last value is 2. What should happen?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Move lo to mid + 1, because the drop must be right of mid
Right: 7 > 2 means the sequence wraps somewhere after mid.
A middle value above the right end proves the wrap point lies to the right, so the left half can be dropped.
Why not the others?
- B Move hi to mid, because 7 is large. The minimum cannot be at or left of a value bigger than the right end here.
- C Return 2, the last value. The smallest value, 0, is before the end.