why we prefer mid = start + ( end - start ) /2 in certain cases instead of mid = (start + end) / 2
what is the concept of integer overflow?
why we prefer mid = start + ( end - start ) /2 in certain cases instead of mid = (start + end) / 2
what is the concept of integer overflow?
@chaman9 integer overflow occur when you try to store a number in a variable of size greater than it can store for example
range of int data type is -2^32 to 2^32-1
if you will try to store number greater than this than you will get integer overflow
still how that first formula will help me?
@chaman9
as you can see if your array size is 10^5
and now you apply the second formula there is a chance that it will overflow for int data type,
but since in second formula you are dividing the difference of two numbers and then adding so it will not overflow
okay thanks i got this