GCSE · Computer Science · AQA · Spec 8525
Compare linear and binary search
Nobody finds a word in a dictionary by reading from 'aardvark'. You open it near the middle and jump, and that only works because it's in order.
Computer Science · Searching
Two ways to find 38
One sorted list, searched twice. Keep an eye on the comparisons count and the output at the bottom.
Before you press Next: which search will find 38 in fewer comparisons? Have a guess at both counts.
1 LINEAR: check each item in turn2 not 38 → move to the next item3 38 → found, stop4 BINARY: compare with the mid-point5 38 → found, stop6 38 > mid → keep the right half7 38 < mid → keep the left half
Variables
Output
Step 1: Here's our list, already in order, smallest first. Both searches hunt for the same number: 38. Linear search goes first, and it starts at the very front.
Step with Next, or press Play. The · marks are items binary search has thrown away.
Predict, then check
Same seven numbers as the hero, just jumbled.
The list is now 31 4 47 22 9 38 15, not in order. A binary search looks for 9, which is definitely in there. What happens?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
One checks every item in turn. The other throws away half the list with each comparison, but only if the list is in order.
What you need to know
- A linear search checks each item in a list one at a time, starting from the first.
- Order doesn't bother it: a linear search works on data in any order.
- It copes with lots of types of data too, including strings like names and words.
Have a goYour mate has a jumbled list of 200 pet names and announces: "Linear search is useless here. The names aren't in order, and they aren't even numbers." Right or wrong?
Wrong on both counts.
Linear search just asks 'is this the one?' of each item in turn, so neither a jumbled order nor strings get in its way.
- Linear search's best case: the item you want is the very first one.
- Its worst case: the item is the last one, or not in the list at all, so every item gets checked.
Have a goA linear search runs on the list 7 3 9 1. How many comparisons does it make before it can say that 5 isn't there?
4: every single item.
It can't stop early. Until it has checked the last item, 5 might still be there, which is why 'not in the list' is a worst case.
- A binary search compares the search item with a mid-point, then discards half of the remaining data.
- Then it repeats that compare-and-discard step on whatever is left, until the item is found.
Have a goOrdered list: 3 8 12 20 25 31 40. A binary search for 31 compares it with the mid-point, 20. Which items are still in play afterwards?
25 31 40
31 is bigger than 20 and the list is in order, so 31 can only be to the right. Keeping 3 8 12 is the classic wrong-half slip.
- Binary search only works on an ordered list. Unordered data? Use a linear search, or sort the data first.
- On average, a binary search finds an item in less time than a linear search. On average, not every time.
The big picture
A linear search checks each item in a list one at a time, so it works on data in any order, including strings. A binary search compares the item with a mid-point and discards half of the remaining data with each comparison. That makes it quicker on average, but it can only be used on an ordered list.
Key points
Worked example
Problem
A list holds these names, in this order: Priya, Tom, Aisha, Leo, Maya. Choose a suitable search to find Leo, trace it, and give the best and worst case for this list.
⚠ Watch out
Forgetting that 'not in the list at all' is a worst case for linear search too. A search for nothing feels like it should be quick. It isn't: the search can't stop early, so it has to check every item before it can say the item isn't there.
Memory hook
Linear walks the line. Binary chops it in half, but only if the line is in order.
Check yourself
No peeking: in two sentences, explain why binary search can throw away half the list after one comparison, and what would stop that from working.
Flashcards
(11)What does a linear search do?
Does a linear search need the data to be in order?
What types of data can a linear search be used on?
When does a linear search make its fewest comparisons, and when its most?
What does a binary search do?
What must be true of a list before you use binary search?
Why does binary search need ordered data?
Your data is unordered. What are your two options?
List in order, smallest first. The search item is bigger than the mid-point. What gets discarded?
Which search is quicker on average, and why?
Is binary search quicker on every single search?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 28 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.