How do we measure and compare the efficiency of algorithms independently of the machine they run on?
Analyse the time and space complexity of an algorithm using Big-O notation, and compare common growth rates
A focused answer to the H2 Computing outcome on algorithmic complexity. Big-O notation, deriving the order of growth from loops and recursion, the common complexity classes, and the trade-off between time and space.
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
SEAB wants you to analyse how an algorithm's running time and memory use grow with the input size, expressed in Big-O notation, and to compare the common growth rates. The central idea is that Big-O describes the order of growth as the input gets large, ignoring machine speed and constant factors, so two algorithms can be compared independently of the hardware.
The answer
What Big-O measures
Big-O notation describes an upper bound on how the cost of an algorithm grows as the input size grows. It captures the dominant term and drops constants and lower-order terms, because for large those do not matter:
We care about getting large because that is where efficiency differences become decisive.
Reading complexity off code
Count how the number of basic operations scales with :
- A single loop over items is .
- A loop nested inside another, each over , is .
- Halving the problem each step gives .
- Splitting into halves and doing linear work to combine gives .
# O(n): one pass
for x in data:
process(x)
# O(n^2): nested passes
for i in data:
for j in data:
compare(i, j)
The common complexity classes
From fastest-growing (worst) to slowest-growing (best) for large :
- constant - independent of .
- logarithmic - halving each step (binary search).
- linear - one pass.
- - good comparison sorts (merge sort).
- quadratic - nested loops (bubble sort).
- exponential - infeasible beyond small .
Time versus space
Complexity applies to time (operations) and space (extra memory). They often trade off: an algorithm can run faster by using more memory (for example storing precomputed results), or use less memory by recomputing and running slower.
Examples in context
Example 1. Why search engines do not scan everything. A linear scan of billions of web pages per query would be in the size of the index - far too slow. Search engines build indexes that allow near- or constant-time lookups, which is the whole reason results return in milliseconds.
Example 2. Choosing a sort in practice. A teaching example might use bubble sort () for clarity, but a library sorting a million records uses an algorithm. The difference is not academic: at , the quadratic version does roughly a trillion operations versus about twenty million for .
Try this
Q1. State the Big-O time complexity of summing all elements of a list of numbers. [1 mark]
- Cue. - one pass adds each element once.
Q2. Reduce to standard Big-O form. [1 mark]
- Cue. - keep only the dominant term, drop constants and lower-order terms.
Q3. An algorithm halves its input each step. State and justify its time complexity. [2 marks]
- Cue. - the number of steps is the number of times can be halved, which is .
Exam-style practice questions
Practice questions written in the style of SEAB exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
Original5 marksState the Big-O time complexity of each of the following and justify briefly: (a) finding the maximum of an unsorted list of items; (b) a nested loop where the outer runs times and the inner runs times; (c) binary search on a sorted list of items.Show worked answer →
(a) . You must inspect every element once to be sure of the maximum, so the work grows linearly with .
(b) . The inner loop runs times for each of the outer iterations, giving basic operations.
(c) . Binary search halves the search range each step, so the number of steps is the number of times can be halved, which is .
Markers reward each correct class with a one-line justification: linear because every item is seen once, quadratic because of the nested loop, logarithmic because the range halves.
Original5 marksTwo algorithms solve the same problem: Algorithm A runs in time using extra space; Algorithm B runs in time using extra space. (a) Which is faster for very large , and why? (b) Give a situation where you might still prefer Algorithm A. (c) Explain what space means.Show worked answer →
(a) Algorithm B is faster for very large , because grows much more slowly than ; as increases the quadratic term dominates and A's running time pulls far ahead of B's.
(b) You might prefer A when memory is very tight or is small. A uses only constant extra space, so on a device with little memory, or for small inputs where the constant factors make A competitive, A can be the better choice.
(c) space means the extra memory used does not grow with the input size - the algorithm needs only a fixed number of variables regardless of how large is.
Markers reward identifying B as asymptotically faster with the growth-rate reason, a valid trade-off favouring A (low memory or small n), and a correct definition of constant space.
Related dot points
- Implement and trace linear search and binary search, state their complexities, and justify when each applies
A focused answer to the H2 Computing outcome on searching. Linear search and binary search, tracing each on an example, their O(n) and O(log n) complexities, and the precondition that binary search needs sorted data.
- Implement and trace bubble sort and insertion sort, analyse their complexity, and compare their behaviour on nearly sorted data
A focused answer to the H2 Computing outcome on elementary sorts. Bubble sort and insertion sort, tracing each on an example, their O(n squared) worst case, and why insertion sort excels on nearly sorted input.
- Explain and trace merge sort and quicksort as divide-and-conquer algorithms, analyse their complexity, and compare their trade-offs
A focused answer to the H2 Computing outcome on efficient sorts. Merge sort and quicksort as divide-and-conquer, their O(n log n) behaviour, quicksort's worst case, and the trade-off between stability, memory and speed.
- Define recursion in terms of base and recursive cases, trace recursive calls, and compare recursion with iteration
A focused answer to the H2 Computing outcome on recursion. Base and recursive cases, tracing the call stack, the divide-and-conquer pattern, and the trade-offs between recursion and iteration.
- Implement and trace breadth-first and depth-first traversal of a graph, and contrast the two strategies and their applications
A focused answer to the H2 Computing outcome on graph traversal. Breadth-first search with a queue and depth-first search with a stack or recursion, tracing each on a graph, and choosing between them for shortest paths and exploration.