Open mohanadtalat91 opened 2 years ago
Overflow will be happen at this line because if end=2147483647 & start=214 then the sum of start+end will be overflow. So try to use the following formula to prevent overflow - - > mid=start+((end-start)/2)
end=2147483647
start=214
start+end
mid=start+((end-start)/2)
https://github.com/amritansh22/Data-Structures-and-Algorithms-in-cpp/blob/1d8ccd7b89ef093f173e80b9a3932104511062e5/SearchingAlgorithms/binary_search.cpp#L14
Thanks for opening your first issue here!
Instead of using mid = (start+end)/2 , use mid = start+((end-start)/2).
Overflow will be happen at this line because if
end=2147483647
&start=214
then the sum ofstart+end
will be overflow. So try to use the following formula to prevent overflow - - >mid=start+((end-start)/2)
https://github.com/amritansh22/Data-Structures-and-Algorithms-in-cpp/blob/1d8ccd7b89ef093f173e80b9a3932104511062e5/SearchingAlgorithms/binary_search.cpp#L14