Module 2 · Binary Search · Common Mistakes

Binary search: common mistakes

One character in the Range class decides whether a binary search works. Here are the three slips students make most, each on First Bad Version: a range that stops shrinking, a loop that runs once too often, and a step that throws the answer away. The boxes show every version's true colour (green good, red bad) and the dimmed ones are out of the range.

Pick a mistake and press play: Wrong runs the code with the mistake until it breaks, and the code marks the wrong line in red. Fixed runs the corrected code on the same input, with the corrected line in green.

Mistake
Code