All subjects · Computer Science · WCP03 Advanced Principles of Computer Science
Algorithmic efficiency and Big O notation
Edexcel IAL Computer Science · WCP03 Advanced Principles of Computer Science
Big O notation describes how an algorithm's running time grows as the input grows. It lets you compare algorithms without timing them on a particular computer, and it explains why some problems become impossible at scale.
What Big O measures
Big O describes the upper bound on the growth rate of time (or memory) as the input size n increases. It keeps only the dominant term and ignores constants: 3n2 + 5n + 20 is O(n2), because for large n the n2 term swamps the rest.
It is needed to: compare algorithms independently of hardware; predict how a program will cope with much more data; choose a suitable algorithm; spot intractable problems.
The complexity classes
From slowest-growing to fastest-growing. The last column shows how many steps each needs for 1000 items.
| Class | Name | Example | n = 1000, roughly |
|---|---|---|---|
| O(1) | Constant | Accessing an array element by index; hash table lookup (average) | 1 |
| O(log n) | Logarithmic | Binary search; search in a balanced BST | 10 |
| O(n) | Linear | Linear search; traversing a linked list | 1000 |
| O(n log n) | Linearithmic | Merge sort; quick sort (average) | 9966 |
| O(n2) | Polynomial (quadratic) | Bubble sort; insertion sort (worst); nested loops over the data | 1 000 000 |
| O(2n) | Exponential | Brute force over every subset; naive recursive Fibonacci | about 10301 |
Polynomial also includes n3 and higher powers
Best and worst cases
Exam questions often ask for both. The worst case is what Big O usually quotes.
| Algorithm | Best case | Worst case |
|---|---|---|
| Linear search | O(1): target is first | O(n): target last or absent |
| Binary search (sorted data) | O(1): target in the middle | O(log n) |
| Bubble sort (with early stop) | O(n): already sorted | O(n2) |
| Insertion sort | O(n): already sorted | O(n2) |
| Merge sort | O(n log n) | O(n log n) |
| Quick sort | O(n log n) | O(n2): extreme pivots |
| Hash table search | O(1) | O(n): many collisions |
| BST search | O(1): target at root | O(n): unbalanced chain |
Finding the Big O of code
- A single statement: O(1).
- A loop over n items: O(n). Two loops one after the other: O(n) + O(n) = O(n).
- A loop nested inside another, each over n: O(n2); three deep: O(n3).
- A loop that halves (or doubles) its range each pass: O(log n).
- A loop over n containing a halving loop: O(n log n).
- Recursion that makes two calls on n - 1 each time: O(2n).
for i in range(n): # n times
for j in range(n): # n times each
total += i * j # O(1)
# O(n^2)
while n > 1: # halves each time
n = n // 2
# O(log n)Worked example
A sorting algorithm takes 2 seconds for 1000 items and is O(n2). Estimate the time for 3000 items.
- n is multiplied by 3.
- For O(n2), time is multiplied by 32 = 9.
- 2 x 9 = 18 seconds.
Answer: About 18 seconds
Check yourself
- What is the Big O of an algorithm whose number of steps is 4n2 + 10n + 7?
- O(4n2)
- O(n)
- O(n2)
- O(n2 + n)
Show answer
O(n2). Keep the dominant term and drop constants.
- What is the worst-case time complexity of binary search?
- O(log n)
- O(n)
- O(1)
- O(n log n)
Show answer
O(log n). Each comparison halves the remaining items.
- What is the time complexity of a loop over n items nested inside another loop over n items, with O(1) work inside?
- O(2n)
- O(n log n)
- O(n2)
- O(log n)
Show answer
O(n2). n x n iterations.
- What is the time complexity of: while n > 1: n = n // 2?
- O(n)
- O(log n)
- O(n2)
- O(1)
Show answer
O(log n). The number of passes is about log2 n.
- What is the maximum number of comparisons binary search needs for a sorted list of 1000 items?
Show answer
10. 29 = 512 < 1000 <= 1023 = 210 - 1, so at most 10 comparisons.
- An O(n2) algorithm takes 5 ms for 200 items. Estimate the time for 800 items, in ms.
Show answer
80 ms. n x 4, so time x 16: 5 x 16 = 80 ms.
- Merge sort makes about n log2 n comparisons. Estimate this for n = 1024.
Show answer
10240. 1024 x 10 = 10 240.
- Which statement describes linear time, O(n)?
- The running time stays the same however many items there are
- The running time doubles with each extra item
- The running time grows in direct proportion to the number of items
- The running time grows with the square of the number of items
Show answer
The running time grows in direct proportion to the number of items. Double the data, double the time.
Sources
- Pearson Edexcel International Advanced Subsidiary and Advanced Level in Computer Science specification (2026), Issue 1
- Pearson Edexcel IAL Computer Science sample assessment materials (Unit 3 paper, resource booklet and mark scheme)
Last updated 8 November 2026. Spotted a mistake? Tell us.