Codacoda
Back to Academy

searching

Linear Search

Linear Search sequentially checks each element of the list until a match is found or the whole list has been searched. It is the simplest search algorithm and works on both sorted and unsorted data.

Use Cases

  • Small or unsorted datasets
  • When the list is searched only once
  • Simple lookup in unindexed data

Complexity Analysis

MetricBestAverageWorst
TimeO(1)O(n)O(n)
SpaceO(1)

Visualization

Target: 70
10
0
23
1
45
2
70
3
11
4
15
5
Speed:1x
Searching for 70 in the arrayStep 1 / 5

Implementation

Output

Click "Run Code" to see output...