FlowLab Logo

Linear Search Visualizer

SlowFast
715
(10)
Current (Examined)
Target Value
Found
Other
Operation Logs
No operations yet
Algorithm Info
Time Complexity: O(n) - checks each element once
Space Complexity: O(1) - uses constant extra space
Best Case: O(1) - target is the first element
Worst Case: O(n) - target is the last element or not found
How it works: Scans through each element sequentially from left to right until target is found or array ends.
When to use: Unsorted data, small datasets, or when you need to find all occurrences.
Implementation
function linearSearch(arr, target) {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === target) {
      return i;
    }
  }
  return -1;
}