Linear Search (or sequential search) is the simplest searching algorithm. It inspects each element of an array one by one from start to finish until it finds a match for the target value or reaches the end of the list. Unlike binary or jump-based searches, it requires no prior sorting. Linear Search works seamlessly on arrays, linked lists, and streaming inputs.
for i = 0 to (n - 1):
if arr[i] == target: return i
return -1
Control speed:
Metric / Operation | Complexity | Description |
|---|---|---|
| Best Case | O(1) | When the target element is located at the very first index (index 0). |
| Average Case | O(n) | Assuming uniform hit probability, roughly n / 2 elements are inspected before finding the target. |
| Worst Case | O(n) | When the target sits at the last index or is absent, requiring all n elements to be checked. |
| Space Complexity | O(1) | Inspects elements in place using only a constant loop index. |
Linear Search works on unsorted collections, linked lists (where random access is O(n)), and very small arrays where sorting overhead outweighs logarithmic lookup savings.
Sentinel Linear Search temporarily places the target value at the last slot of the array (saving the original element first). Because the target is now guaranteed to be found, the loop no longer needs to check i < n on every iteration, cutting per-step branching in half.
On unsorted arrays or linked lists, self-organizing heuristics such as Move-to-Front (move each found item to index 0) or Transpose (swap it one step closer to the front) reduce average lookup time on skewed workloads.
to join the discussion
Hand-picked resources to deepen your understanding
© 2025 See Algorithms. Code licensed under MIT, content under CC BY-NC 4.0