← Back to the searching page

Linear & Sentinel Search

Scan until found. Unbeatable on unsorted or tiny data, and the baseline every other search is measured against.

What to know

  • No ordering or preprocessing required; works on any iterable.
  • A sentinel copy of the target at the end removes the bounds check per step.
  • Branch prediction makes linear scans of small arrays faster than "smarter" searches.

In the wild: grep over a file, finding an element in a small config list, DOM querySelector fallbacks.

Algorithms to reach for

Linear scan

O(n)

Find in unsorted data, short-circuit on hit

Sentinel search

O(n)

Micro-optimized scan for hot loops

Practice problems — with full guides

Each problem has its own page: progressive hints, how to approach it, and the full solution.