Binary search is one of the first algorithms that people learn. The idea is wonderfully simple: Yet it’s so easy to get the details wrong. In fact, nearly all binary searches are broken. If you set out to write a binary search, you would probably start out with an outline like this: