HN Hall of Fame Weekly email

Nearly all binary search and merge sort implementations are broken (2006)

googleresearch.blogspot.com Essays & writing Essays & articles Computer science Candidate
Screenshot of googleresearch.blogspot.com captured 2026-07-20
Page preview · captured 2026-07-20

Resurfaced independently across 5 calendar years, with breakout response in 2 of them.

submissions
6
submitters
6
observed span
2009–2015
peak thread · 69 comments
148 pts
latest 20+ return · 2012-01-30
148 pts

Submission timeline

2007–2026

One slot for every year since HN launched. Height is that year's peak points; orange marks a 100+ point or 50+ comment breakout. Select a bar to open its strongest thread.

First comments on top threads

HN comment order

It is not sufficient merely to prove a program correct; you have to test it too. Moreover, to be really certain that a program is correct, you have to test it for all possible input values, but this is seldom feasible. This statement is tantamount to saying "you don't merely need to prove Fermat's Last Theorem, you also have to test it for all possible input values". By this line of reasoning, most of mathematics should be thrown out. If…

It's not binary searches and merge sorts that are broken, it's the INT data type that is "broken" (and I put "broken" in scare quotes because they aren't really broken, they just don't do what you want in most cases). People tacitly assume that INTs model the integers, but they don't. They model the integers modulo 2^N for some value of N. If you code as if INTs were integers and you hit the 2^N limit you will lose. The…

lisper·101-point thread·

Not just binary search. Anything that involves addition of signed integers could overflow.

bigbang·21-point thread·

I remember when this came out. I looked at the code for Binary Search & Merge Sort that I had written for a Data Structures and Algorithms class I was teaching at the time. Neither of these had the bug. The reason was that I was using C++ iterators. template<typename RAIter> void mergeSort(RAIter first, RAiter last); So I could not do RAIter middle = (first + last) / 2; because the there is no operator+ on iterators in general. Instead…

The first top-level comment from each of the four biggest threads, in HN’s own order. Excerpts are shortened; open a comment for full context.

Breakout years
2

100+ points or 50+ comments

Total points
285

reference only — not used in Hall rules or ranking

Total comments
131

reference only — not used in Hall rules or ranking

Every submission