GCSE · Computer Science · Edexcel · Spec 1CP2

Evaluating algorithm efficiency

Two searches. Same list. Same target. One needs 8 goes, the other needs 4. So the faster one always wins, right? Not quite. That's what this lesson is about.

Algorithms · Efficiency

Same list, same target: which search does less work?

Eight planets in alphabetical order. We're hunting for Venus, the last one. Each step adds one comparison to the trace table: rows 1 to 8 are linear search, rows 9 to 12 are binary search. The highlighted planet is the one being compared with Venus.

Before you step through: how many comparisons do you reckon each search will need to find Venus? Make a guess for both.

1 Earth
2 Jupiter
3 Mars
4 Mercury
5 Neptune
6 Saturn
7 Uranus
8 Venus
searchcompared with Venusmatch?planets left to searchcomparisons so far
linearEarthno81

Output

 

Step 1: Linear search starts at the front. Earth? Nope. One comparison down.

1 / 12

This is a trace table: it records the values step by step. Count its rows and you've counted the comparisons. That's how a trace helps you check how efficient an algorithm is.

Step 1 of 12: Linear search starts at the front. Earth? Nope. One comparison down..

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.
Watch out: When binary search has two middle items to choose from, this trace always takes the left-hand one. Take the right-hand one instead and the planets compared change, so always use the rule you're given.

Efficiency · Doubling the data

Double the list. What happens to binary search?

The sorted list grows from 8 items to 16. What's the most comparisons binary search could now need to find an item? Commit to a number.

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, every pass full lengthvsImproved bubble sort

Quick reminder: bubble sort goes through the list comparing each pair of neighbouring items and swaps them if they're the wrong way round. One trip through the list is a pass. Start with the top row: that's where the two versions really part company. Open each row's insight to see why.

Focus

Comparisons in each pass

Bubble sort, every pass full length

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 insight

A pass compares every neighbouring pair it covers, so a 5-item list has 4 pairs to check. Without the improvement, every pass checks all 4, even pairs at the end that are already settled. With it, each pass checks one pair fewer than the last.

The largest item after a pass

Bubble sort, every pass full length

Reaches its final place at the end, but is still compared on every later pass

Improved bubble sort

Reaches its final place at the end and is left alone from then on

The sorted result

Bubble sort, every pass full length

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 its 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. Know how two differ and you'll spot when one suits better.
  • Searches are compared by counting comparisons. The worst case is the highest number of comparisons possible on a given list.
  • Have a goA linear search finds its item on the very first comparison. Is that its worst case?

    No. That's the fewest comparisons it could make.

    The worst case is the most comparisons possible on that list, not whatever happened on one lucky run.

  • Linear search checks each item one at a time, ordered list or not. Worst case: every item compared, so double the list, double that.
  • Binary search needs ordered items. Each comparison discards half the remaining data, so doubling the list adds at most one comparison.
  • Have a goSam's 300-song playlist is in a completely random order. Sam is sure binary search will find a song fastest. What's the catch?

    Binary search needs the songs in order. Linear search works on them as they are.

    Halving only works because the order tells you which half to throw away. With no order, Sam's binary search can't decide.

  • Sorted list of eight planets: linear search's worst case (Venus) takes 8 comparisons. Binary search's worst case takes just 4.
  • Linear search is simpler to write; binary search is longer and more complex, as it can take different paths. Data and context decide.
  • A trace table tracks variable values and the flow of execution step by step, which helps you check how efficient an algorithm is.
  • Bubble sort swaps neighbouring items that are in the wrong order. Each pass makes (items − 1) comparisons; passes repeat until one makes no changes.
  • Have a goAn ascending bubble sort reaches the neighbouring pair 8, 3 in the middle of a pass. What happens to them, and where does the pass go next?

    Swap them to 3, 8, then compare the next neighbouring pair.

    They're neighbours in the wrong order, so they swap. A pass doesn't stop at one swap: it carries on to the end of the list.

  • Bubble sort is one of the slowest sorts, especially on large data. Improve it: stop after a no-swap pass, and make one fewer comparison each pass.
  • Picking a sorting algorithm? Weigh its efficiency on large data, how easy it is to implement and test, its memory needs and the data's format.

The big picture

Two algorithms can do the same job with very different amounts of work. Compare searches by counting comparisons in the worst case: on a sorted list of eight planets, linear search needs 8 and binary search needs 4, because each binary comparison discards half of what's left. Double the list and linear search's worst case doubles; binary search needs at most one more. But binary search needs ordered data and is harder to write, so the choice depends on data and context. Bubble sort is one of the slowest sorts; stopping after a no-swap pass and making one fewer comparison each pass cut its waste.

Key points

1Count comparisons, and compare searches 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. It feels fair: twice the items, twice the work. But that's only linear search. Binary search needs at most one more comparison, because its first comparison halves the doubled list straight back down.

🧠

Memory hook

Double the list: linear DOUBLES, binary adds ONE. Then ask the second question: is the data even in order?

✓

Check yourself

A sorted list has 32 items. What's linear search's worst case? Binary search needed at most 5 for 16 items, so what now? Give one reason to still choose linear search.

Flashcards

(16)
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 full 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.
Why can the improved bubble sort make one fewer comparison after each pass?
Each pass moves the largest item not yet in place to its final position at the end, so it never needs comparing again.
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 31 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.