Programming & syntax · reviewed in August 2026
Algorithmic complexity
Algorithmic complexity describes, using Big O notation, how the time (or memory) an algorithm needs grows as its input size grows. It doesn't measure exact seconds, but the growth trend: O(n) grows linearly, O(n²) grows much faster.
# O(n): a single pass
def contains(items, value):
return value in items
# O(n^2): compares every pair of elements
def has_duplicates(items):
for i, a in enumerate(items):
for b in items[i + 1:]:
if a == b:
return True
return FalseFrequently asked questions
What does O(n) mean versus O(n²)?
O(n) means work grows proportionally to input size (walking a list once); O(n²) means it grows with the square, typical of comparing every element against every other one — much slower on large inputs.
Why does it matter if the code 'already works'?
Because an O(n²) algorithm can be instant with 100 items but take minutes with a million; complexity predicts how the code will behave as data grows, which testing with small data doesn't reveal.
How do you spot an algorithm's own complexity?
By counting how many times the most expensive operation runs relative to input size — for example, a loop nested inside another loop over the same data usually signals O(n²).