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.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
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 , an algorithm always beats an 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 , an algorithm does about 1000 steps, an one about 10 000, an one about a million, and an 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 . A single loop over items is ; a loop nested inside another is ; repeatedly halving gives . Constants and lower-order terms are dropped, so is and is .
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 in space; merge sort allocates temporary sublists proportional to the input, so it is in space. Recursive algorithms also consume memory on the call stack, one frame per level of recursion, so a recursion that goes levels deep has 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 times; a loop that doubles or halves a variable each time runs 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 times, giving an term. The separate single loop runs times, giving an term. The total is .
In Big-O notation only the dominant term is kept, because for large the term grows far faster than the term and the term becomes negligible. So the complexity simplifies to .
Markers reward identifying the from the nested loops, the from the single loop, and the rule that the dominant term is kept (so the answer is ).
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 , 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 : the target is the first item examined, so one comparison is enough. The worst case is : the target is the last item or is absent, so all 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 and values for linear search with reasons.
Related dot points
- Understand the linear search and binary search algorithms, how each works, their requirements, and their time complexity.
A focused answer to AQA A-Level Computer Science 4.3.2, covering the linear search and binary search algorithms, how each works, the requirement that binary search needs sorted data, and their time complexity.
- Understand the bubble sort and merge sort algorithms, how each orders a list, their time complexity, and the trade-off between them.
A focused answer to AQA A-Level Computer Science 4.3.3, covering the bubble sort and merge sort algorithms, how each works, their time complexity, and the trade-off between simplicity and efficiency.
- Understand tractable and intractable problems, the classes P and NP, the idea of computable and non-computable problems, and the use of heuristics for intractable problems.
A focused answer to AQA A-Level Computer Science 4.4.6 and 4.4.7, covering tractable and intractable problems, the classes P and NP, computable and non-computable problems, and the use of heuristics to tackle intractable problems.
- Understand Dijkstra's shortest path algorithm, how it finds the lowest-cost path from a start vertex, the role of a priority queue, and its applications.
A focused answer to AQA A-Level Computer Science 4.3.4, covering Dijkstra's shortest path algorithm, how it finds the lowest-cost path from a start vertex in a weighted graph, the role of a priority queue, and its applications.
- Understand the Turing machine model, its components, the idea of a universal Turing machine, and the link to the limits of computation and the halting problem.
A focused answer to AQA A-Level Computer Science 4.4.5, covering the Turing machine model and its components, the transition rules, the universal Turing machine, and its link to computability and the halting problem.
Sources & how we know this
- AQA A-level Computer Science (7517) specification — AQA (2015)