Year 10 (ages 14–15, Grade 9 in the US) · Computing · GCSE programming · Lesson 15
Searching algorithms: linear and binary search
How linear search and binary search work, writing a linear search in Python, tracing a binary search, and comparing the two algorithms by efficiency and requirements.
Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

8-minute video lesson
Teaching, worked examples and 20 practice questions solved step by step.
Watch free for a monthWhat your child will learn
- Describe linear search
- Write a linear search in Python
- Describe and trace binary search
- Compare linear and binary search
The method
- Linear: check each item in turn from the start.
- Binary: list must be sorted; check the middle.
- If target < middle, discard the upper half; else the lower.
- Repeat until found or no items left.
Key words: algorithm, linear search, binary search, midpoint, efficiency.
Worked examples
Worked examples from the lesson, with every step.
Question 1
Linear search for 8 in [5, 2, 8, 1]. How many comparisons?
- Step 1: 5? no. 2? no. 8? yes.
- Step 2: 3 comparisons
Answer: 3
Question 2
Binary search for 23 in [3, 8, 12, 17, 23, 31, 40]. First middle?
- Step 1: 7 items → index 3 → 17
- Step 2: 23 > 17 → keep right half
Answer: 17
Question 3
Continue: right half is [23, 31, 40]. Next step?
- Step 1: 31
- Step 2: 23 < 31 → left: [23] → found
Answer: found after 3 comparisons