I have come across multiple problems which use variations of binary search to reach the final answer. These problems include finding floor of square root of
It's not like there are worse and better options that you've mentioned. Usually it just depends on a implementation, e.g. if you pass high=arr.length
then you'd rather write while(low < high)
than while(low <= high)
.
In fact, some of those differences may have a meaning. If we consider binary search algorithm to find your X number in an array A and there will be some (not only one) elements equal to X, you can both find index of the first one or the last one - it depends on a implementation.