Pattern

Complexity analysis

Reason precisely about time and space cost — amortized, worst-case, and where a "worse" big-O actually wins.

What it is

This label covers problems that test whether you can derive a cost bound rather than just quote one: computing the amortized cost of a sequence of operations, explaining why a data structure's advertised complexity can degrade under adversarial or pathological input, and recognizing when a asymptotically "worse" algorithm is actually faster for the sizes and shapes of input you'll really see. The answer usually has two halves: a precise argument (a sum, an accounting scheme, a worst-case construction) and a runnable demonstration that the argument's prediction matches measured behavior.

When it applies

Tells in the problem

The classic mistake

Treating big-O as if it settles the question on its own, without checking what it hides: an O(n²) algorithm can beat an O(n log n) one when n is small or the input is already nearly sorted, because O(n²) analysis hides a tiny constant and no allocation, while O(n log n) hides recursion overhead and buffer allocation that dominate at small scale. The same blind spot runs the other way — quoting "hash table lookup is O(1)" without the caveat "amortized, and only if the hash function resists the key distribution you'll actually see" is exactly the gap that lets a hash-flooding attack turn O(1) into O(n) per operation. The fix in both directions is to say which regime the bound holds in (worst case vs. amortized vs. average case, over which input distribution) rather than reciting the bound alone.

Questions to start with

All 6 complexity analysis questions

Problem statement, examples and hints are free on every page; the worked approach, solution and tests are in the company guides.

Free starter pack

13 must-tier questions with full solutions

Sign in with an email — no purchase — and read them in the full reader.

No password, no spam. One sign-in email; you can read the pack in the full reader.