Codele / Algorithms
Linear search
You lost one card in a row of cards. The plainest way to find it is to check the cards one by one, from the left, until you meet it or run out.
- Linear search checks the items one by one from the start, until it finds the one it wants or reaches the end.
- It works on any row, sorted or not. That is its strength.
- To say “not there” it must look at every item.
- The number of looks grows with the length of the row: that is O(n).
- Counting looks is how we compare search methods.
Loading the playable lesson…