Beginner · Interactive lesson

Linear search

Check one value at a time. Search any array and discover why order matters.

The interactive player is loading. If it does not appear, you can still read the explanation below.

THE IDEA BEHIND THE STEPS

How it works

Linear search checks values from left to right. It works on unsorted arrays and stops at the first match. If every value has been checked without a match, the target is absent.

Watch the index pointer and the dimmed cells that have been ruled out. A match at the beginning takes one comparison; a missing target requires checking every value. Worst-case time is O(n), best-case time is O(1) for a nonempty array, and extra algorithm space is O(1). The visualization stores steps for replay separately.

Duplicates are allowed: this version returns the first matching index. An empty array has no match and needs no comparisons.