Array search
Halves a sorted range each step by comparing the middle element to the target, discarding the half that can't contain it.
Searching for:Binary Search: O(log n)
6121419202531354244505661626669767985919394100102104105109116118119
Real-time /ps log
lo = 0, hi = n-1while lo <= hi:mid = (lo + hi) / 2if arr[mid] == target: return midif arr[mid] < target: lo = mid + 1else: hi = mid - 1return NOT_FOUND
Comparisons: 0Found at index: —Theoretical steps: log₂(30) ≈ 4.9