KS3 · Computer Science
Linear vs binary search
Looking up 'penguin' in a dictionary, you don't read from page one. You open it near the middle, see where you've landed, and jump. That's a search algorithm in disguise.
Computing · Searching algorithms
Binary search: check the middle, bin half
A sorted list of 15 numbers, and we're hunting for 45. Step through and watch the list shrink. A dot (·) is an item that has been thrown away.
Before you press Next: guess how many checks it will take to find 45.
1 Start with the whole sorted list2 REPEAT3 Check the middle item of what is left4 IF middle item = target THEN stop: found it5 IF target < middle item THEN bin the middle item and everything above it6 IF target > middle item THEN bin the middle item and everything below it7 UNTIL target found OR nothing is left
Variables
Output
Step 1: Here's the sorted list: 15 numbers, smallest to biggest. We want 45. No checks yet — so how would you start?
Press Next to go one step at a time, or Play to watch it run. Every value is written into the lesson — the page isn't running any code.
Computer Science · Algorithms
Trace table — dry run the code
Same list, same target, the other way: start at the front and check every item in turn. Watch the checks column.
Ready when you are — step through one line at a time.
Computing · Choosing a search
So which search should you use?
Choose a branch at each level to reach a decision.
Is the list sorted? → What kind of job is it?
4 situations.
Walk the route that matches your list. For any one list, only one route is true.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Two ways to find something in a list — and why one of them barely slows down when the list doubles
What you need to know
- What a search algorithm does, and how to count its checks
- How linear search works, and why it works on any list
- How binary search works, and why it needs a sorted list
- Why halving makes binary search so fast on long lists
- How to choose the better search for a job
The big picture
A search finds whether a target is in a list, and where; we compare searches by counting checks. Linear search checks each item in turn from the first. It works on any list, but may have to check every item. Binary search only works on a sorted list: check the middle, bin it and the half that can't hold the target, repeat. Each check removes about half of what's left, so doubling the list adds only about one more check. On long sorted lists binary search is much faster; for a short list, or an unsorted list searched once, linear search can be the better choice.
Key points
Worked example
Problem
Use binary search to look for 20 in this sorted list: 4, 9, 13, 18, 22, 27, 31. Which items get checked, and what does the search find?
⚠ Watch out
Binning the wrong half. If the target is bigger than the middle item, it can only be above it: keep the top part, and bin the middle item and everything below. Smaller? Keep the bottom part. Say it as you go: 'bigger — keep the top'.
Memory hook
Linear walks the line, one by one. Binary splits in two and bins a half — but only on a list that's in order.
Check yourself
No peeking: which search works on an unsorted list? After checking the middle item, what does binary search bin? And when a sorted list doubles, roughly how many extra checks does binary search need?
Flashcards
(13)What does a search algorithm do?
How can you compare how efficient two searches are?
How does linear search work?
Does linear search need a sorted list?
What must be true before you can use binary search?
Binary search: which item do you check first?
Binary search: the middle item isn't the target. What do you throw away?
When does a binary search stop?
Linear search, worst case: how do its checks grow with the list's length?
Binary search: what does doubling the length of a sorted list do to the most checks needed?
Why is it called 'binary' search?
When can linear search be the better choice?
When is binary search the better choice?
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 KS3 Computer Science topics
- Abstraction in computational thinking
- Adding binary numbers
- Binary to denary conversion
- Boolean logic: AND, OR, NOT
- Bubble sort
- Building truth tables
- Client-server vs peer-to-peer
- Collecting and recording data
- Comparing sorting algorithms
- Compressing data
- Creating a 3D animation
- Decomposition: splitting problems up
How this lesson was checked. This KS3 Computer Sciencelesson 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 1 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.