Linear search
About this lesson: Linear search
In short
The names are face down. Flip cards to find the target, then let the computer search the same cards. Who needs fewer checks? Play a few rounds.

What you'll explore
- You vs the computer: Find the name
- The names are face down. Flip cards to find the target, then let the computer search the same cards. Who needs fewer checks? Play a few rounds.
- Linear search: One card at a time
- A linear search compares each item with the target, starting at position 0.
- Not found: When the item isn't there
- If the target isn't in the list, the search must check every card before it can say “not found”. Search for Tom, then for Sam, and count the checks.
- How long does it take?: Bigger lists, more checks
- With a long list, a linear search may need many checks. The worst case is when the item is last or missing. Make the list longer and compare the bars.
- Check yourself: Count the checks
- A list holds 20 names. A linear search looks for a name that is not in the list.
Also in this lesson
- Common mix-ups
- Searches you use every day
- Linear search in pseudocode
- Card search
Words to know
- search
- Look for an item in stored data.
- target
- The item being searched for.
- linear search
- Checking items one after another from the start.
- index
- The position of an item in a list, usually counted from 0.
- comparison
- Checking whether two values are the same.
Sources
- BBC Bitesize KS3 Computing: Searching algorithms