Complexity and Big-O Notation
Aligned to the AQA 7517 specification
- Level
- Intermediate
- Reading time
- 6 min
- Published
- 13 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- Big-O notation describes the asymptotic upper bound on a function's growth rate as n approaches infinity, ignoring constant factors and lower-order terms.
- The growth classes rank O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(n³) < O(2ⁿ) < O(n!) for large n.
- To derive Big-O: a single loop is O(n), two nested loops O(n²), halving the input O(log n); sequential blocks take the highest order and constant multipliers are dropped.
- For large n an O(n log n) algorithm is always faster than an O(n²) algorithm regardless of constant factors, so merge sort beats bubble sort at scale.
- Big-O applies to space as well as time: bubble sort uses O(1) space while merge sort needs O(n), illustrating a time–space trade-off.
How much of this have you taken in?
Quiz yourself on this section, free, no card needed.
Key terms
- Big-O notation
- Notation describing the asymptotic upper bound on the growth rate of a function as n approaches infinity, ignoring constant factors and lower-order terms.
- Asymptotic
- Describing behaviour of a function's growth rate as the input size n tends towards infinity.
- Constant — O(1)
- A complexity class where running time does not depend on input size, such as accessing an array element by index.
- Logarithmic — O(log n)
- A complexity class where the input size is halved or reduced by a constant factor each step, such as binary search.
- Linear — O(n)
- A complexity class with one operation per input element, such as a linear search reading every element once.
- Polynomial — O(nᵏ)
- A complexity class produced by k nested loops; two nested loops give O(n²) and three give O(n³).
- Exponential — O(kⁿ)
- A complexity class where the work multiplies with each unit increase in n, growing too fast to be practical beyond small inputs.
- Factorial — O(n!)
- A growth class following f(n) = n!, such as brute-force travelling salesman trying all permutations.
- Time complexity
- How an algorithm's running time grows as the input size increases.
- Space complexity
- How an algorithm's memory use grows with input size; O(1) is fixed memory and O(n) grows proportionally.
Frequently asked questions
Big-O notation compares algorithms by how their time or space requirements grow as input size increases, independent of hardware speed and specific constant factors. It describes the asymptotic upper bound on growth as n approaches infinity, ignoring constant factors and lower-order terms.
A single loop over n elements is O(n), two nested loops over n are O(n²) and k nested loops O(nᵏ), halving the input each step is O(log n). For sequential non-nested blocks take the highest order, and drop constant multipliers, so O(5n) = O(n).
Merge sort is O(n log n) and bubble sort is O(n²). Since log n is much smaller than n, an O(n log n) algorithm is always faster than an O(n²) one for large n, regardless of constant factors.
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
BNF and Syntax Diagrams
Limits of Computation and Tractability
Related lessons
5 min
6 min
6 min