Linear Search

Check each element in turn until the target is found. Slower than binary search, but it makes no demands on the data: the array does not have to be sorted, which is the one thing binary search cannot do without.

time O(n) worst, O(1) best
space O(1)

Press Tab out of the box or click Resetto regenerate frames from the current input.

Visualization
No frames yet — edit input and click Run.
—
Pseudocode
for i in 0..n-1:
  if a[i] == target:
    return i
return -1