Loading subject…
| Complexity | n = 10 | n = 100 | n = 1000 |
|---|---|---|---|
| O(1) | 1 | 1 | 1 |
| O(log n) | 3 | 7 | 10 |
| O(n) | 10 | 100 | 1000 |
| O(n log n) | 33 | 664 | 9966 |
| O(n²) | 100 | 10000 | 1000000 |
| O(2ⁿ) | 1024 | about 1.3 × 10³⁰ | more atoms than the observable universe |
| Algorithm | Best case | Average case | Worst case | Space |
|---|---|---|---|---|
| Linear search | O(1) | O(n) | O(n) | O(1) |
| Binary search | O(1) | O(log n) | O(log n) | O(1) |
| Bubble sort | O(n) | O(n²) | O(n²) | O(1) |
| Selection sort | O(n²) | O(n²) | O(n²) | O(1) |
These four algorithms are constructed and traced in B2.4.2 and B2.4.3; this page covers only how their cost is measured and compared.