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 Earth
2 Jupiter
3 Mars
4 Mercury
5 Neptune
6 Saturn
7 Uranus
8 Venus

Variables

match?=nochecking=Earthalgorithm=linear searchcomparisons=1looking for=Venus

Output

 

Step 1: Linear search starts at the front. Is Earth the planet we want? No. That's one comparison.

1 / 12

This is a trace: tracking the values step by step. Tracing an algorithm like this is how you check how efficient it is.

Step 1 of 12: Linear search starts at the front. Is Earth the planet we want? No. That's one comparison..

Exam line: Compare searching algorithms by their worst-case number of comparisons. On this sorted list of eight planets: linear search 8, binary search 4.

Efficiency · Doubling the data

Double the list. What happens to binary search?

A sorted list grows from 8 items to 16. What is the most comparisons binary search could now need to find an item?

Your estimate

8 comparisons

0 comparisons16 comparisons

Evaluating algorithms

Is binary search always the better choice?

The claim

Binary search is always the better choice of searching algorithm.

Place each piece of evidence to load the balance. Mark the strong ones — they count double.

  1. On the sorted list of eight planets, binary search needed 4 comparisons in the worst case. Linear search needed 8.

    Evidence 1: does it support or challenge the claim?
  2. Double the size of a sorted list and binary search needs at most one more comparison, while linear search's worst case doubles.

    Evidence 2: does it support or challenge the claim?
  3. Binary search only works if the items in the list are in order. Linear search works whether they're ordered or not.

    Evidence 3: does it support or challenge the claim?
  4. Binary search is longer and more complex to write, because the algorithm can take different paths. Linear search just steps through the data in order.

    Evidence 4: does it support or challenge the claim?

Exam line: A strong evaluation names the efficiency advantage AND the conditions that limit it, then reaches a judgement that depends on the data and context.

Bubble sort: making a slow algorithm less wasteful

Bubble sort without the improvementsvsImproved bubble sort

Quick reminder: bubble sort goes through the list comparing each pair of neighbouring items and swaps them if they're in the wrong order. One trip through the list is called a pass, and passes are repeated. Open each row's insight to see why the change works.

Focus

Checking for swaps

Bubble sort without the improvements

Doesn't keep track of whether a pass made any swaps

Improved bubble sort

Keeps track, and stops as soon as a pass makes no swaps

The insight

A pass with no swaps means every neighbouring pair is already in the right order, so the list is sorted. Any further pass would be wasted work.

Comparisons in each pass

Bubble sort without the improvements

Always the number of items minus one: a 5-item list gets 4 comparisons every pass

Improved bubble sort

One fewer after each pass: 4, then 3, then 2, then 1

The sorted result

Bubble sort without the improvements

A list in order

Improved bubble sort

The same list in order

Put it into words

Choosing a sorting algorithm

A developer needs to sort a very large list of customer records and is thinking of using bubble sort. Explain why bubble sort might be a poor choice here, and give two other factors the developer should consider when choosing a sorting algorithm. [3 marks]

0 words · your answer stays on this page and is not sent anywhere.

Exam line: For 'why might this be a poor choice?', say what the algorithm is bad at. For 'what else should they consider?', name separate factors.

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

1Count comparisons, and compare algorithms on their worst case.
2Eight sorted planets: linear search 8 comparisons, binary search 4.
3Double the list: linear search's worst case doubles; binary search needs at most one more.
4Binary search needs ordered data and is harder to write, so 'more efficient' doesn't always mean 'better choice'.
5Improved bubble sort stops after a pass with no swaps and makes one fewer comparison each pass.

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?
By the number of comparisons: how many times the search item is compared with an item in the list.
What is the worst-case scenario for a searching algorithm?
The highest number of comparisons possible on a given list of data.
How does a linear search work?
It checks each item in the list one at a time to see if it's the right item.
Linear search: what happens to the worst case if the list doubles?
It doubles too, because in the worst case every item is compared.
How does a binary search work?
It discards half of the remaining data with each comparison, and repeats until the item is found or the data is exhausted.
Binary search: what happens to the worst case if the list doubles?
It needs at most one more comparison.
Sorted list of eight planets: worst-case comparisons for each search?
Linear search: 8 (for Venus, the last planet). Binary search: 4.
Which search needs the data to be in order?
Binary search. Linear search works on ordered or unordered data.
Which search is simpler to write, and why is the other one harder?
Linear search is simpler. Binary search is longer and more complex because the algorithm can take different paths.
What decides which searching algorithm is more suitable?
The data and the context you're using it in, not efficiency alone.
How can a trace table help you evaluate an algorithm?
It tracks the values of variables and the flow of execution step by step, so you can check how efficient the algorithm is.
How does bubble sort work?
It goes through the list comparing neighbouring items and swapping them if they're in the wrong order. Each trip through the list is a pass.
How many comparisons does one bubble sort pass make?
The number of items in the list minus one.
Two ways to make bubble sort more efficient?
Stop once a pass makes no swaps, and make one fewer comparison after each pass.
Factors to consider when choosing a sorting algorithm?
Efficiency on large data, how easy it is to implement and test, how much memory it needs, and how the data is formatted.

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 posted

More Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

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.