Skip to main content
EnglandComputer ScienceSyllabus dot point

How do we measure and compare the efficiency of algorithms?

Understand Big-O notation for time and space complexity, the common orders of growth, how to determine the complexity of an algorithm, and the meaning of best, average and worst case.

A focused answer to AQA A-Level Computer Science 4.3.5, covering Big-O notation for time and space complexity, the common orders of growth, determining the complexity of an algorithm, and best, average and worst case.

Generated by Claude Opus 4.88 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. What Big-O measures
  3. The common orders of growth
  4. Determining complexity, and best/worst case

What this dot point is asking

AQA wants you to use Big-O notation to express the time and space complexity of an algorithm, recognise the common orders of growth, work out an algorithm's complexity from its structure, and explain best, average and worst case.

What Big-O measures

Time complexity measures how the number of operations grows; space complexity measures how the additional memory used grows. The reason constants are dropped is that they depend on the hardware and the language, whereas the order of growth is an intrinsic property of the algorithm. For large enough nn, an O(nlogn)O(n \log n) algorithm always beats an O(n2)O(n^2) one regardless of constant factors, which is what makes Big-O a fair comparison.

The common orders of growth

To get a feel for the gap: at n=1000n = 1000, an O(n)O(n) algorithm does about 1000 steps, an O(nlogn)O(n \log n) one about 10 000, an O(n2)O(n^2) one about a million, and an O(2n)O(2^n) one a number with hundreds of digits. This is why exponential algorithms are described as intractable: doubling the input size squares the work.

Determining complexity, and best/worst case

To find complexity, identify how many times the dominant operation runs in terms of nn. A single loop over nn items is O(n)O(n); a loop nested inside another is O(n2)O(n^2); repeatedly halving gives O(logn)O(\log n). Constants and lower-order terms are dropped, so 3n+53n + 5 is O(n)O(n) and n2+nn^2 + n is O(n2)O(n^2).

The best case is the fewest operations (for example the target found first), the worst case is the most (target last or absent), and the average case is the expected behaviour over typical inputs. Big-O usually quotes the worst case because it guarantees an upper bound on the running time, which is what matters when you need a guarantee that the algorithm will finish in time.

Space complexity is measured the same way but counts additional memory rather than operations. An in-place algorithm such as bubble sort uses only a constant amount of extra space, so it is O(1)O(1) in space; merge sort allocates temporary sublists proportional to the input, so it is O(n)O(n) in space. Recursive algorithms also consume memory on the call stack, one frame per level of recursion, so a recursion that goes nn levels deep has O(n)O(n) space complexity even if it appears to use little memory in its body. This is why an algorithm can be excellent on time but unacceptable on memory, and why the specification asks you to consider both dimensions.

A common exam skill is reading complexity straight from a structure without running it. A loop that increments a counter by one each time runs O(n)O(n) times; a loop that doubles or halves a variable each time runs O(logn)O(\log n) times; two independent loops run one after the other add, giving the dominant of the two; loops nested inside each other multiply, giving a product. Recognising these patterns lets you classify most exam algorithms in a few seconds, which is the intended outcome of this part of the specification.

Exam-style practice questions

Practice questions written in the style of AQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

AQA 20194 marksAn algorithm contains a single loop nested inside another loop, each running n times, followed by a separate single loop that also runs n times. Determine the Big-O time complexity of the whole algorithm and justify your answer.
Show worked answer →

The nested loops execute the inner body n×n=n2n \times n = n^2 times, giving an O(n2)O(n^2) term. The separate single loop runs nn times, giving an O(n)O(n) term. The total is O(n2+n)O(n^2 + n).

In Big-O notation only the dominant term is kept, because for large nn the n2n^2 term grows far faster than the nn term and the nn term becomes negligible. So the complexity simplifies to O(n2)O(n^2).

Markers reward identifying the n2n^2 from the nested loops, the nn from the single loop, and the rule that the dominant term is kept (so the answer is O(n2)O(n^2)).

AQA 20213 marksExplain the difference between the best case and the worst case time complexity of an algorithm, using linear search as an example.
Show worked answer →

The best case is the smallest number of operations the algorithm performs for an input of size nn, and the worst case is the largest number. They describe how the running time depends on the particular input, not just its size.

For linear search, the best case is O(1)O(1): the target is the first item examined, so one comparison is enough. The worst case is O(n)O(n): the target is the last item or is absent, so all nn items are compared. Big-O figures usually quote the worst case because it bounds the time guaranteed to be enough.

Markers reward defining best and worst case and giving the correct O(1)O(1) and O(n)O(n) values for linear search with reasons.

Related dot points

Sources & how we know this