I was recently going through the question of finding the square root of a number using binary search. In the code, we implement one condition to check if the square of the mid point is less than or greater than the value whose square root we have to find. Instead of writing,
if(mid * mid > num) where, num is the no. whose square root we have to find out,
we write,
if(mid > num / mid) in order to avoid overflow.
Can anybody tell me how does the overflow happen and how, by writing in the num/mid helps in avoiding overflow ?