BUG LAB · Binary search
The search that never ends
This search uses a closed interval. Which input makes the loop stop making progress?
Java · intentionally broken snippet
while (left <= right) {
int mid = left + (right - left) / 2;
if (a[mid] == target) return mid;
if (a[mid] < target) left = mid;
else right = mid - 1;
}Assume ordinary supporting code and valid inputs unless the question states otherwise.
Choose an answer before revealing the trace. Keys 1 to 3 work too.