|
|
|
|
|
by rustybolt
1561 days ago
|
|
I agree that binary search is prone to errors, but the overflow error is just calculating the midpoint as (low + high) / 2
I mean, that's technically true because it might crash for huge arrays, but if this is a bug then the follow implementation of a function that adds to integers is also buggy, since it will overflow when x + y doesn't fit in an int: int add(int x, int y) { return x + y; }
|
|
There's nothing about the signature of an ordinary binary search method that would imply that it only works for arrays that have less than MAX_INT/2 elements.