Re:Nearly All Binary Searches and Mergesorts Are Broken (2006)
by legosexmagic on Sunday November 06, 2022 @12:09PM
(#33494742)
the right solution is to parametrize the search region as (offset, length) instead of (start, end).
then the midpoint is just offset+length/2.
youll also want to remove that unpredictable branch in the loop.
[ Parent
| on HN ]
Re:Nearly All Binary Searches and Mergesorts Are Broken (2006)
by abecedarius on Sunday November 06, 2022 @07:55PM
(#33499643)
(offset, length) was how I coded it in the 90s, too, precisely because it made correctness clearer. "Nearly all" broken, hmph.