3 ms·
> int mid = low + ((high - low) / 2); Why this instead of the more intuitive `low/2 + high/2` ? Edit: Nevermind, I get it. The reason is instructive: In the
by Cpoll 10y ago
> int mid = low + ((high - low) / 2);
Why this instead of the more intuitive `low/2 + high/2` ?
Edit: Nevermind, I get it.
The reason is instructive: In the case where high and low are odd numbers, the "more intuitive" way is off by one.