The idea
Scan until you find it
Linear search walks an array from index 0 to the end. At each position it asks: “Is this the value I’m looking for?”
If yes — stop. If no — move to the next index. Worst case you check every element; best case you find it first.
TipWorks on unsorted data. Binary search needs sorted data; linear search does not.
IdeaCore loop
linear_search.pyPython
for i in range(len(arr)): if arr[i] == target: return i return -1
Array: [3, 8, 1, 7, 4] · Target: 7
Interactive
Run the simulation
The highlighted cell is the one being compared to the target.
demo.pyPython
Array + variablesdemo
Ready
Shortcuts: Space play/pause · → step · ← back · R reset
Remember
When to use linear search
It’s the right tool when the list is small or unsorted.
O(n)
Time grows with size
In the worst case you look at every element once — fine for short lists, slow for huge ones.
No prep
No sorting required
Unlike binary search, the array can be in any order.
Early exit
Stop when found
You don’t keep scanning after a match — that saves work on average.