Search Visualizer
Searching
Compare direct scanning with range-halving search. Each step shows the active search space, eliminated indexes, and the synced code line.
O(log n)
Index 018
Index 129
Index 236
Index 342
Index 454
Index 567
Index 673
Index 791
Step Note
Sort the values and search the first index that can hold the target.
This visualizer displays a sorted copy of the input values.
function lowerBound(array: number[], target: number) {
let left = 0
let right = array.length
while (left < right) {
const mid = Math.floor((left + right) / 2)
if (array[mid] >= target) {
right = mid
} else {
left = mid + 1
}
}
return left
}