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(n)
Index 042
Index 118
Index 267
Index 329
Index 491
Index 554
Index 636
Index 773
Step Note
Start scanning from the first item.
function linearSearch(array: number[], target: number) {
for (let index = 0; index < array.length; index++) {
if (array[index] === target) {
return index
}
}
return -1
}