4 ms·
> mid = ((unsigned int)low + (unsigned int)high)) >> 1; Also not correct if the sum overflows.
by beyondCritics 2y ago
> mid = ((unsigned int)low + (unsigned int)high)) >> 1;
Also not correct if the sum overflows.
- poincaredisk 2y agoIt can't overflow - max_int+max_int < max_uint
- deleted 2y ago[deleted]
- tda 2y agoSo does the bitshift cast the result of the addition to an unsigned int? I am not so familiar with Java.
- beyondCritics 2y agoThis reasoning is correct but still has to assume that both indices are non negative, which is reasonable.