Step 0 / 0 · Comparisons: 0 · Swaps: 0
How this algorithm works
How it works
- Start at the first element of the list.
- Compare the current element to the target value.
- If they match, the search succeeds — return the current index.
- Otherwise, move to the next element and repeat the comparison.
Key concepts
- No ordering requirement (works on unsorted data)
- Sequential, exhaustive scan in the worst case
- Best case O(1) when the target is the first element
- Foundation for understanding why sorted-data algorithms like binary search exist
When to use it
When the data is unsorted, small, or searched only once — sorting first just to binary-search would cost more than a single linear pass.
Did you know
Despite its simplicity, linear search is provably optimal for unsorted data: no comparison-based algorithm can guarantee better than O(n) without first sorting or indexing.