4 ms·
In that case, then you can to go back to int mid = (low + high) / 2; but you'd have to constrain low and high to be in the range [-2^30, 2^30 - 1] so as t
by cbhl 9y ago
In that case, then you can to go back to
int mid = (low + high) / 2;
but you'd have to constrain low and high to be in the range [-2^30, 2^30 - 1] so as to not overflow a (assuming 32-bit) signed integer. (And you're probably using 64-bit floating point, or similar, which has other fiddly bits.)
However, the article specifically talks about merge sort in arrays, so low (your "a") is always >= 0. The discovery was "oh, we went decades before someone had to sort an array with more than 2^31 elements". Frankly, it's akin to when we ran out of IPv4 addresses -- when it was originally built, there was some range over which the computation was defined to be correct, and we later discovered that we wanted to do computation outside that range.