Year 9 (ages 13–14, Grade 8 in the US) · Computing · Algorithms · Lesson 1
Linear search
How a linear search works, tracing it, counting comparisons, best and worst cases, and writing it in Python.
Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

20-minute video lesson
Teaching, worked examples and 20 practice questions solved step by step.
Watch free for a monthWhat your child will learn
- Describe a linear search
- Trace a linear search
- Count comparisons
- Read linear search code
The method
- Start at position 0.
- Compare with the target.
- Match? Stop. No? Next item.
- Count the comparisons.
Key words: algorithm, linear search, comparison, index, worst case.
Worked examples
Worked examples from the lesson, with every step.
Question 1
Use a linear search to find 9 in the list [7, 3, 9, 2, 5, 8]. How many comparisons are needed?
- Step 1: Start at position 0
- Step 2: Check each item in turn
Answer: found at position 2 after 3 comparisons
Question 2
Use a linear search to find 7 in the list [7, 3, 9, 2, 5, 8]. How many comparisons are needed?
- Step 1: Start at position 0
- Step 2: Check each item in turn
Answer: found at position 0 after 1 comparison
Question 3
Use a linear search to find 8 in the list [7, 3, 9, 2, 5, 8]. How many comparisons are needed?
- Step 1: Start at position 0
- Step 2: Check each item in turn
Answer: found at position 5 after 6 comparisons