GCSE · Computer Science · Edexcel · Spec 1CP2
Evaluating algorithm efficiency
One search checks every item in turn. Another throws away half the list with every look. Which is better? 'The fast one, obviously' is only half the answer.
Algorithms · Efficiency
Same list, same target: which search does less work?
Eight planets in alphabetical order, and we're looking for Venus, the last one. Steps 1 to 8 are linear search; steps 9 to 12 are binary search. The highlighted line is the planet being compared with Venus.
Before you press Next: how many comparisons do you think each search will need to find Venus?
1 Earth2 Jupiter3 Mars4 Mercury5 Neptune6 Saturn7 Uranus8 Venus
Variables
Output
Step 1: Linear search starts at the front. Is Earth the planet we want? No. That's one comparison.
This is a trace: tracking the values step by step. Tracing an algorithm like this is how you check how efficient it is.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Don't guess which algorithm is faster. Count the comparisons, then ask whether faster is actually the right choice.
What you need to know
- An algorithm is a set of step-by-step instructions to solve a problem. Describing how two algorithms differ lets you recognise when one is more suitable than another.
- The efficiency of searching algorithms is compared by the number of comparisons. The worst case is the highest number of comparisons possible on a given list.
- Linear search checks each item one at a time. In the worst case every item is compared, so doubling the list doubles its worst case. It works on ordered or unordered data.
- Binary search discards half of the remaining data with each comparison, until the item is found or the data runs out. Doubling the list adds at most one comparison. The items must be in order.
- On a sorted list of eight planets: linear search's worst case (Venus) is 8 comparisons; binary search's worst case is 4.
- Linear search is simpler to write; binary search is longer and more complex because the algorithm can take different paths. Which search suits best depends on the data and context.
- Tracing an algorithm with a trace table, which tracks the values of variables and the flow of execution step by step, helps you check how efficient it is.
- Bubble sort compares neighbouring items and swaps them if they're in the wrong order. Each trip through the list is a pass, and a pass makes (number of items − 1) comparisons.
- Bubble sort is one of the slowest sorting algorithms, especially on large data. Improve it by stopping when a pass makes no swaps, and by making one fewer comparison after each pass (the largest item has reached its final place).
- Choosing a sorting algorithm depends on factors such as efficiency on large data, how easy it is to implement and test, how much memory it needs, and how the data is formatted.
The big picture
Algorithms doing the same job can do very different amounts of work. For searching, count the comparisons in the worst case: on a sorted list of eight planets, linear search needs 8 and binary search needs 4, because each of its comparisons discards half of what's left. Double the list and linear search's worst case doubles, while binary search needs at most one more. But binary search needs ordered data and is harder to write, so the better choice depends on data and context. Bubble sort is one of the slowest sorting algorithms; stopping after a no-swap pass, and making one fewer comparison each pass, makes it more efficient.
Key points
Worked example
Problem
Use the improved bubble sort to put 5, 2, 7, 3, 9 into ascending order. How many comparisons does it make?
⚠ Watch out
Thinking that doubling the list doubles binary search's comparisons too. Only linear search's worst case doubles; binary search needs at most one more comparison, because each comparison halves what's left.
Memory hook
Double the list: linear DOUBLES, binary adds ONE. Then ask the second question: is the data in order?
Check yourself
A sorted list has 32 items. What's linear search's worst case, and how many more comparisons might binary search need than for 16 items? Give one reason to still choose linear search.
Flashcards
(15)How is the efficiency of searching algorithms compared?
What is the worst-case scenario for a searching algorithm?
How does a linear search work?
Linear search: what happens to the worst case if the list doubles?
How does a binary search work?
Binary search: what happens to the worst case if the list doubles?
Sorted list of eight planets: worst-case comparisons for each search?
Which search needs the data to be in order?
Which search is simpler to write, and why is the other one harder?
What decides which searching algorithm is more suitable?
How can a trace table help you evaluate an algorithm?
How does bubble sort work?
How many comparisons does one bubble sort pass make?
Two ways to make bubble sort more efficient?
Factors to consider when choosing a sorting algorithm?
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 Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)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 29 September 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.