GCSE · Computer Science · AQA · Spec 8525

Algorithm efficiency

Two programs print exactly the same answer. One of them did ten times the work to get there. Can you tell which, without a stopwatch?

Watch the work pile up

Two ways to add up 1 to 10

Both methods get the right answer. The question is how much work each one does to get there. count A and count B tally the calculations each method carries out: every +, × or ÷ counts as one.

Before you press Play: which method do you think will do more work?

1 // Method A: add the numbers one at a time
2 total ← 0
3 FOR i ← 1 TO n
4 total ← total + i
5 ENDFOR
6 OUTPUT total
7 // Method B: use a formula
8 answer ← n * (n + 1) / 2
9 OUTPUT answer

Variables

n=10total=0count A=0count B=0

Output

 

Step 1: Same job for both methods: add up 1 + 2 + 3 + … + 10. Method A starts its running total at 0. Nothing has been added yet, so count A is 0.

1 / 16

Press Next, or Play, and keep your eye on count A and count B.

Step 1 of 16: Same job for both methods: add up 1 + 2 + 3 + … + 10. Method A starts its running total at 0. Nothing has been added yet, so count A is 0..

What does 'efficient' actually mean?

Whose algorithm is more efficient?

Jess and Sam each write a program that adds up the numbers from 1 to 10. Both programs print 55. Jess runs hers on a brand-new laptop and it finishes first. Sam runs his on an old school computer and it finishes later.

Whose algorithm is more efficient? Pick the idea that's closest to what you think right now.
How sure are you?

Predict, then check

Back to Methods A and B from the top of the page.

Try n = 3. Method A does 3 additions (1 + 2 + 3), and Method B does 3 calculations. It's a dead heat! Now make n = 1,000. What happens to the two counts?

When the data changes the work

Best case, worst case, or in between?

How many characters does the algorithm have to check for each password? Sort each one.

Still to sort

Best case (0)

The fewest checks possible: just 1.

Where the line is: Best case means the work stops as early as it possibly can, at the very first character.

Worst case (0)

The most checks possible: all 6.

Where the line is: Worst case isn't only 'no digit'. Any password that forces all 6 checks is a worst case.

In between (0)

More than 1 check but fewer than 6.

Where the line is: These stop part-way through: more work than the best case, less than the worst.

6 of 6 still to sort.

A new job. An algorithm checks whether a 6-character password contains a digit. It looks at the characters one at a time from the left, and stops as soon as it finds a digit. If it reaches the end without finding one, the answer is no. Method A always did one addition per number; this algorithm's work depends on the password itself.

Your turn to explain

Explain the winner

Algorithm P FOR i ← 1 TO 70 IF i MOD 7 = 0 THEN OUTPUT i ENDIF ENDFOR Algorithm Q k ← 7 WHILE k ≤ 70 OUTPUT k k ← k + 7 ENDWHILE

Both algorithms output the multiples of 7 from 7 to 70. Explain why Algorithm Q is more efficient than Algorithm P. [4 marks]

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

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Two algorithms can both get the right answer while one of them does far more work. Efficiency is about counting that work.

What you need to know

  • A problem can usually be solved by several algorithms. All can be correct, yet need very different amounts of work.
  • Efficiency means how quickly an algorithm completes its task, judged by counting its basic steps, such as comparisons or loop repetitions.
  • Count steps, not seconds. The count doesn't depend on the hardware, so the comparison is fair.
  • To compare two algorithms, count the steps each one carries out on the same input.
  • Have a goBen announces: 'My count is 8 steps and Ana's is 80, so I win!' Ben's list had 8 names. Ana's had 80. Why is Ben getting ahead of himself?

    Their counts come from different inputs, so they can't be compared yet.

    A fair comparison counts both algorithms on the same input; a smaller list can give a smaller count whichever algorithm is used.

  • Then see how each count grows as the input gets bigger. The count that grows more slowly belongs to the more efficient algorithm.
  • Have a goAlgorithm S takes 10 steps on 10 items and 20 steps on 20 items. Algorithm T takes 10 steps on 10 items and 400 steps on 20 items. Which count is growing more slowly?

    S's count: it goes from 10 to 20, while T's jumps from 10 to 400.

    They start level, so the starting point can't separate them. What matters is what each count does as the input gets bigger.

  • The more efficient algorithm does less to reach the same result, for example checking fewer items or repeating a loop fewer times.
  • The number of steps can depend on the data. Best case is the fewest steps possible; worst case is the most steps possible.
  • Have a goYour lost sock is somewhere in a drawer of 9 socks. You check them one at a time from the top and stop when you find it. How many socks do you check in the best case, and in the worst case?

    Best case 1 sock (it's on top). Worst case 9 socks (it's at the very bottom).

    Best and worst case depend on where the work stops: the fewest checks possible and the most checks possible.

  • Efficiency differences matter most with large amounts of data. On a small input, two algorithms may perform similarly.

The big picture

Most problems can be solved by more than one algorithm, and every one of them can be correct while needing very different amounts of work. We judge efficiency by counting basic steps, like comparisons or loop repetitions, not by timing a program on one particular computer. To compare two algorithms, count the steps each does on the same input, then see how those counts grow as the input gets bigger: the count that grows more slowly belongs to the more efficient algorithm. The data itself can change the step count, which is why we talk about best and worst cases.

Key points

1Same answer doesn't mean same work.
2Count steps, not seconds.
3Give both algorithms the same input before you compare their counts.
4Name the work the winner skips.
5Best case: the work stops as early as possible. Worst case: the most work possible.
6Tiny inputs can hide the difference; big inputs show it up.

Worked example

Problem

Two algorithms decide whether a whole number n is even. Algorithm X keeps subtracting 2 from n until what's left is 0 or 1; if it's 0, n is even. Algorithm Y works out n MOD 2 once; if the result is 0, n is even. For n = 12, count the steps each algorithm needs. Which is more efficient, and why?

⚠ Watch out

Comparing two algorithms on different inputs, for example one on a list of 5 items and the other on a list of 500. The step counts only mean something when both algorithms get the same input.

🧠

Memory hook

Don't time it, count it. Then make the input bigger and count again.

✓

Check yourself

Cover the page. What does efficiency measure, and why not just time it? How do you compare two algorithms fairly? What are best and worst cases? Why does big data matter?

Flashcards

(10)
Can two different algorithms both give the correct result for the same problem?
Yes. And they can still need very different amounts of work to get there.
What does an algorithm's efficiency mean in this topic?
How quickly it completes its task, judged by how many basic steps it carries out.
Why count steps instead of timing a program?
Timing depends on the computer it runs on. A step count doesn't, so it gives a fair comparison.
Give two examples of basic steps you could count.
Comparisons, and repetitions of a loop.
What must be the same when you compare two algorithms' step counts?
The input. Both algorithms must be counted on the same data.
Judged by growth, which of two algorithms is more efficient?
The one whose step count grows more slowly as the input gets bigger.
Where does the more efficient algorithm's advantage come from?
The work it avoids, such as checking fewer items or repeating a loop fewer times.
What's the difference between an algorithm's best case and its worst case?
Best case: an input needing the fewest steps possible. Worst case: an input needing the most.
When do differences in efficiency matter most?
With large amounts of data. On a small input, two algorithms may perform about the same.
Does a shorter program always do less work?
No. A short loop can repeat many times. Count the steps carried out, not the lines written.

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 AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

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 23 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.