Skip to content
StackDecode
SearchingAnimated

Linear Search

Check each element in turn until the target is found.

Time

O(n)

Extra space

O(1)

Use it for

Unsorted or tiny lists.

How it works

  1. Start at the first element.
  2. Compare it with the target. If equal, stop: found.
  3. Otherwise move to the next element.
  4. If you run past the end, the target is not in the list.
  5. No ordering is needed, but in the worst case every element is checked.

Watch it run

Loading animation…