Computational complexity describes how the time or memory requirements of an algorithm grow as the size of the input (n) increases. It is used to compare the efficiency of different algorithms.
In Edexcel 1CP2, you need to understand and compare the following complexities:
Big-O notation describes the worst-case growth rate of an algorithm. The common complexities you need to know are:
| Complexity | Name | Example | n=10 steps (approx) |
|---|---|---|---|
| O(1) | Constant time | Accessing an array by index | 1 |
| O(log n) | Logarithmic time | Binary search | 3–4 |
| O(n) | Linear time | Linear search | 10 |
| O(n log n) | Log-linear time | Merge sort | ~33 |
| O(n²) | Quadratic time | Bubble sort (worst case) | 100 |
| Algorithm | Best case | Worst case | Requirement |
|---|---|---|---|
| Linear search | O(1) — first item is target | O(n) — target not present | None |
| Binary search | O(1) — target is midpoint | O(log n) | Sorted list |
| Algorithm | Best case | Worst case |
|---|---|---|
| Bubble sort (basic) | O(n²) | O(n²) |
| Bubble sort (optimised) | O(n) — already sorted | O(n²) |
| Merge sort | O(n log n) | O(n log n) |
For small inputs, the difference between O(n) and O(n²) is negligible. But for large inputs (e.g. n = 1,000,000), an O(n²) algorithm would require 10¹² steps — making it practically unusable — while O(n log n) requires only ~20 million steps.
8 Edexcel-style questions · AI-marked
| Term | Definition |
|---|
Timed exam-style test. No feedback until submission.