Binary Search
42 / 170Binary SearchLesson 4 of 8About 45 min
Binary search needs a reason to throw away a half, and sortedness is only one possible reason.
Run find_peak on [1, 2, 1, 3, 5, 6, 4]. For each pass give mid, the comparison result as rising or falling, and the range afterward as low and high.
| pass | mid | slope | low after | high after |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.