Linear search (also called sequential search) is a searching algorithm that checks each element in a list one by one, from the first to the last, until either the target is found or the entire list has been checked.
It works on any list — sorted or unsorted. It is the simplest searching algorithm.
Target = 7
Step 1: Check 3 ≠ 7 → move on
Step 2: Check 1 ≠ 7 → move on
Step 3: 7 = 7 ✓ Found at index 2!
| i | list[i] | list[i] = target? | found | position |
|---|---|---|---|---|
| 0 | 3 | False | False | -1 |
| 1 | 1 | False | False | -1 |
| 2 | 7 | True | True | 2 |
| 3 | 9 | False | True | 2 |
| 4 | 4 | False | True | 2 |
Returns: 2 (target found at index 2)
| Case | Comparisons | Example (n=10) |
|---|---|---|
| Best case | 1 | Target is the first element |
| Average case | n ÷ 2 | ~5 comparisons |
| Worst case | n | 10 comparisons (last or not found) |
For n = 1,000,000 items, linear search needs up to 1,000,000 comparisons in the worst case.
| Advantages | Disadvantages |
|---|---|
| Works on unsorted lists | Slow for large lists (up to n comparisons) |
| Simple to implement and understand | Less efficient than binary search on sorted data |
| No preprocessing needed | Not suitable for very large datasets |
8 AQA-style questions · 22 marks · AI marks your answers and gives feedback
| Term | Definition |
|---|
Timed exam conditions. No feedback until you submit.