GCSE · Computer Science · AQA · Spec 8525
Algorithm efficiency
Two programs can print exactly the same answer while one does far more work to get there, and on big data that gap can get huge.
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 time2 total ← 03 FOR i ← 1 TO n4 total ← total + i5 ENDFOR6 OUTPUT total7 // Method B: use a formula8 answer ← n * (n + 1) / 29 OUTPUT answer
Variables
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.
Press Next, or Play, and keep your eye on count A and count B.
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.
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.
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 more than one algorithm. They can all give the correct result but need very different amounts of work.
- An algorithm's efficiency is about how quickly it completes its task, judged by counting its basic steps (such as comparisons or loop repetitions), not by timing it on one particular computer.
- Counting steps is a fair comparison because the count doesn't depend on the hardware.
- To compare two algorithms, count the steps each one does on the same input, then look at how that count grows as the input gets bigger. The one whose count grows more slowly is more efficient.
- The more efficient algorithm reaches the same result by doing less, for example checking fewer items or repeating a loop fewer times.
- The number of steps can depend on the data. The best case is the fewest steps possible; the worst case is the most steps 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 they can all be correct while needing very different amounts of work. We judge an algorithm's efficiency by counting the basic steps it carries out, like comparisons or loop repetitions, rather than timing it on one particular computer. To compare two algorithms, count their steps on the same input, then look at how those counts grow as the input gets bigger: the one whose count grows more slowly is more efficient. The step count can also depend on the data itself, which is why we talk about best and worst cases.
Key points
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?
What does an algorithm's efficiency mean in this topic?
Why count steps instead of timing a program?
Give two examples of basic steps you could count.
What must be the same when you compare two algorithms' step counts?
Judged by growth, which of two algorithms is more efficient?
Where does the more efficient algorithm's advantage come from?
What's the difference between an algorithm's best case and its worst case?
When do differences in efficiency matter most?
Does a shorter program always do less work?
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 AQA GCSE Computer Science topics
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 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.