🔎 Finding a needle: linear search
Why: Meet linear search — the honest workhorse that checks everything, one by one.
Unlocks: Binary search — the same job in a millionth of the steps.
Half of everything computers do is finding things: a contact in your phone, a word in a document, a song in a library. The simplest recipe is the one you'd use for lost keys: check every place, one by one, until you find it. Computer scientists call it linear search.
Three runs, three costs: 1 check if you're lucky, 6 if you're not. The worst case — the number professionals actually plan around — is the full length of the list. Six names? Fine. Now imagine the list is every phone number in your country.
A list holds 1,000,000 unsorted names. In the worst case, how many checks does linear search need?
One more honest virtue: linear search needs no preparation. The list can be in any order — chaos is fine. Hold that thought, because the fast method in the next lesson will demand a price.
When is linear search actually the RIGHT choice?