Binary Search

Binary search is the most incorrectly implemented algorithm in production code. Not because it is hard to understand. Because it is hard to get right.

Jon Bentley tested professional programmers — 90% got binary search wrong when writing it from scratch. Java's Arrays.binarySearch shipped with an overflow bug for nine years. Three lines, three landmines: the loop condition, the midpoint, the pointer update.

The Elimination Game

Fifteen cells. Sorted. Target = 11. Tap any cell to reveal its value. No pointers, no automation — you choose where to look.

target = 11
Comparisons:0/ 8 to find it left-to-right