AlgoThrive
← All searching algorithms

Linear Search

CheckingRuled outFound

array

target = 18
7
2
14
9
4
18
11
5
0
1
2
3
4
5
6
7

pseudocode

linearSearch(a, target)
for i from 0 to n-1
if a[i] == target
return i
return -1

Frame 1 / 8

Looking for 18

scan from the left

4

Pick a value that is in the array — or one that isn't, to watch the search fail.

3–16 integers between 1 and 20.