Is there a benefit of writing this binary algo with the line “while low + 1 <= high” instead of while low <= high and in the division adding +1 or -1 to the low or high? I ask because I find it harder to remember to add 1 to the while and to also check for the left after the while loop breaks. Below is the code that I am referring to instead of the example. I just want to know if I am missing some benefit. Thanks.
high = x
low = 0
while low <= high:
mid = (low + high)//2
mid_sqr = mid * mid
if mid_sqr <= x:
low = mid + 1
else:
high = mid -1
return low -1