$./linearsearch
preset:
2 step/s
# algorithm
1linearSearch(A, n, target)
2begin
3 for i0 to n-1 do
4 if A[i] = target then
5 return i
6 return -1 // not found
7end
# search target
Looking for:
62
# array visualization
34
0
7
1
23
2
32
3
5
4
62
5
14
6
28
7
91
8
45
9
checking checked (≠) found (=) unchecked
# variables
i
A[i]
target
62
# progress
checked
0
remaining
9
# current comparison
No active comparison
# current action
select a preset and click "run" to begin...
# array (unsorted)
[34,7,23,32,5,62,14,28,91,45]
# complexity note

Linear Search: O(n) — must check each element sequentially

Binary Search: O(log n) — but requires sorted array

For this 10-element array: Linear checks up to 10 elements, Binary would check ~4