learn/Algorithms/Linear Search
ƒ(x) SearchingCore interactive

Linear Search

Check each element until you find the target.

linear_search
step 1 / 15
4
0
7
1
9
2
21
3
24
4
29
5
39
6
42
7
43
8
52
9
59
10
78
11
83
12

Scan left to right for 83.

cursoreliminatedfound
speed1×
target = 83

How it works

Linear search walks the collection one element at a time. It needs no ordering and works on anything iterable, but it's O(n) — the baseline every faster search is measured against.

Mental models

  • The only option on unsorted data.
  • No preprocessing required.

Complexity

Best
O(1)
Average
O(n)
Worst
O(n)
Space
O(1)