Linear Search scans elements sequentially one-by-one from the start of an array to the end until the target item is found or the array ends.
Compare arr[0] (14) with target 42. 14 != 42 -> Move to next index.
arr[0] = 14 != 42 -> Increment index to 1Compare arr[1] (28) with target 42. 28 != 42 -> Move to next index.
arr[1] = 28 != 42 -> Increment index to 2Compare arr[2] (42) with target 42. 42 == 42 -> Target found!
arr[2] = 42 == 42 -> Return Index 2Looking for keys in a messy drawer by checking every single pocket one by one from top to bottom.
500 steps (Linear)
O(N) Linear Time
O(1) / O(N) Space
Memory growth rate as N expands.
Relative efficiency rating for large N.
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Best Case (First Item) | O(1) | O(1) |
| Average Case | O(N) | O(1) |
| Worst Case (Last / Absent) | O(N) | O(1) |
function linearSearch(arr, target) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === target) return i;
}
return -1;
}Scans raw unsorted user input streams.
Extremely fast for small arrays under 15 elements due to CPU cache locality.
Validate your conceptual understanding, operation mechanics, and core concepts of Linear Search.
Linear search requires zero preprocessing or sorting, making it ideal for single-use searches over small unsorted arrays!
Array loaded. Enter a search target and click Search.