When to use low < high or low + 1 < high for loop invariant
问题 I've read multiple articles including Jon Bentleys chapter on binary search. This is what I understand about CORRECT binary search logic and it works in the simple tests I did: binarysearch (arr, low, high, k) 1. while (low < high) 2. mid = low + (high - low)/2 3. if (arr[mid] == k) return mid 4. if (arr[mid] < k ) high = mid -1 5. else low = mid + 1 Now to find the 1st occurence with sorted duplicates, you'd chance line 3 if condition to continue instead of returning mid as binarysearch_get