Loading...
Explore shrinking intervals: the active range, midpoint selection, and directional decisions until target is found or interval collapses.
1function binarySearch(arr, target):2 lo = 0; hi = length(arr) - 13 while lo <= hi:4 mid = (lo + hi) // 25 if arr[mid] == target: return mid6 if arr[mid] < target: lo = mid + 1 else hi = mid - 17 return -1
Each decision halves the interval, guaranteeing logarithmic steps. Visualization emphasizes interval contraction, mid repositioning, and termination condition.