low < high vs low 1 in Binary search
I am confused about the terminating condition of the loop in binary search. I have also seen some solutions where high - low > 1
is used. I need some explanations to understand when to use low < high
, low <= high
and high - low > 1
.
low < high vs low 1 in Binary search
I am confused about the terminating condition of the loop in binary search. I have also seen some solutions where high - low > 1
is used. I need some explanations to understand when to use low < high
, low <= high
and high - low > 1
.
Binary search: is there a scenario where low != high loop condition causes an error?
Here are 2 implementations of Binary search, with the only difference being the for loop condition.
Number of comparison in best, avg and worst case in Binary Search
So I basically want to know what will be the Best, Avg and Worst case no of comparisons taken by Binary Search on a Sorted Array of N elements.
Consider Both cases where the element is present and not present in the Array