Comparing two algorithms
About this lesson: Comparing two algorithms
In short
Algorithm A adds the numbers one by one. Algorithm B uses a formula. Both are correct. Change n and compare how many steps each needs.

What you'll explore
- Same answer, different work: Adding 1 to n
- Algorithm A adds the numbers one by one. Algorithm B uses a formula. Both are correct. Change n and compare how many steps each needs.
- Finding the largest: One pass or sort first?
- To find the largest number, A checks each number once; B sorts the whole list first. Change the list size and compare the comparisons.
- Choosing: Correct, efficient, clear
- Compare two algorithms that test whether a number is prime. First check both are correct, then compare steps and clarity.
- Check yourself: Efficiency
- Both algorithms give the right answer. A takes 1000 steps, B takes 10 steps.
Also in this lesson
- Common mix-ups
- Two solutions
- Card race
Words to know
- efficiency
- How much work an algorithm needs.
- correctness
- Giving the right answer for every valid input.
- maintainability
- How easy code is to understand and change.
- comparison
- Checking two values against each other.
- trace
- Following an algorithm step by step.
Sources
- BBC Bitesize KS3 Computer Science
- Raspberry Pi Foundation, Computing curriculum resources