📄 Paper 1 · 4.4 Theory of Computation
4.4.4a Big-O Notation & Time Complexity
AQA 7517 · A-Level Computer Science · ~20 min read

Time Complexity

Time complexity measures how the running time of an algorithm grows as the input size n increases. It focuses on the rate of growth, not exact times.

We measure the worst case (maximum steps for any input of size n) unless specified otherwise.

Big-O Notation

Big-O notation is a mathematical notation that describes the upper bound of an algorithm's time complexity — how many operations it performs as a function of input size n in the worst case.

  • Constants and lower-order terms are dropped (we care about growth rate only)
  • E.g. 3n² + 5n + 2 → O(n²)

Common Time Complexities

Big-ONameDescriptionExample
O(1)ConstantSame time regardless of nArray index access, hash table lookup
O(log n)LogarithmicHalves problem each stepBinary search
O(n)LinearProportional to nLinear search, single loop
O(n log n)Linearithmicn × log n stepsMerge sort, quicksort (average)
O(n²)QuadraticNested loops over nBubble sort, insertion sort (worst)
O(2ⁿ)ExponentialDoubles with each new elementBrute-force subset enumeration
O(n!)FactorialGrows factoriallyBrute-force TSP, all permutations

Growth rate comparison (small n)

n=10:   O(1)=1, O(log n)≈3, O(n)=10, O(n log n)≈33, O(n²)=100, O(2ⁿ)=1024
n=100:  O(1)=1, O(log n)≈7, O(n)=100, O(n log n)≈664, O(n²)=10000, O(2ⁿ)=huge!

Order from most to least efficient: O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ) < O(n!)

Identifying Complexity from Code

// O(1) — constant time
x = arr[5]

// O(n) — single loop
for i in range(n):
    print(arr[i])

// O(n²) — nested loops
for i in range(n):
    for j in range(n):
        print(arr[i], arr[j])

// O(log n) — halving each iteration
left, right = 0, n-1
while left <= right:
    mid = (left + right) // 2
    if arr[mid] == target: return mid
    elif arr[mid] < target: left = mid + 1
    else: right = mid - 1

Space Complexity

Space complexity measures memory usage as n grows, using the same Big-O notation.

ComplexityExample
O(1) spaceSorting in-place (e.g. bubble sort)
O(n) spaceStoring a copy of the array
O(n²) spaceStoring an n×n matrix
Exam tip: AQA expects you to identify the Big-O complexity of algorithms from code or descriptions, and to compare complexities. Key rules: one simple loop = O(n); nested loop = O(n²); binary search/halving = O(log n); merge sort = O(n log n). Drop constants and lower-order terms. Worst case is assumed unless stated otherwise.
▶
Click through the slides at your own pace. Use arrow keys or click to advance.
Click slide or press arrow keys to navigate

Worksheet — 4.4.4a Big-O Notation & Time Complexity

8 questions · instantly marked · AQA 7517 standard

Q1What does Big-O notation measure? Why are constants dropped?[2]
✅ Mark scheme
Mark scheme
Big-O measures the upper bound / rate of growth of an algorithm's running time with input size n in the worst case [1]; constants are dropped because they become insignificant as n grows very large — we are interested in how the algorithm scales, not the exact count [1].
Q2State the time complexity of binary search and explain why it achieves this.[2]
✅ Mark scheme
Mark scheme
O(log n) [1]; each step halves the search space — the number of steps needed is the number of times n can be halved, which is log₂(n) [1].
Q3What is the time complexity of an algorithm with a single loop from 1 to n, containing a constant-time operation? Justify your answer.[2]
✅ Mark scheme
Mark scheme
O(n) [1]; the loop runs n times, each iteration doing O(1) work, so total work is proportional to n [1].
Q4An algorithm has two nested loops, each from 1 to n. What is its time complexity?[1]
✅ Mark scheme
Mark scheme
O(n²) [1] — the outer loop runs n times, and for each iteration the inner loop runs n times: n × n = n² total operations.
Q5State the time complexity for: (a) merge sort, (b) bubble sort (worst case), (c) hash table lookup.[3]
✅ Mark scheme
Mark scheme
(a) Merge sort: O(n log n) [1]; (b) Bubble sort worst case: O(n²) [1]; (c) Hash table lookup: O(1) [1].
Q6Order these complexities from most to least efficient: O(n²), O(1), O(n log n), O(log n), O(n), O(2ⁿ).[2]
✅ Mark scheme
Mark scheme
O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ) [2 — award 1 for partially correct order with no more than one error].
Q7What is space complexity? Give an example of an O(n) space algorithm.[2]
✅ Mark scheme
Mark scheme
Space complexity measures how memory usage grows with input size n [1]; O(n) space example: storing a copy of an n-element array / merge sort auxiliary array [1].
Q8Why is O(2ⁿ) considered intractable for large n? Give an example of a problem with exponential time complexity.[2]
✅ Mark scheme
Mark scheme
O(2ⁿ) doubles with every additional element — for large n (e.g. n=100) the number of steps is astronomically large and would take longer than the age of the universe [1]; e.g. brute-force knapsack / travelling salesman / all subsets enumeration [1].
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 8
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — Big-O Notation

10 questions · 10 minutes

← 4.4.3 BNF & Syntax Diagrams
30 of 70 · AQA 7517
4.4.4b Tractable & Halting Problem →