Reference

Data structures & costs

Compare operation costs, ordering, invariants and common algorithm notation.

Scope and conventions

Abstract data structures and conventional implementations. Costs use a unit-cost RAM model unless stated; n is item count, V vertices, E edges and k key/output length. Native containers can have different contracts. Expected, amortized and worst-case bounds are distinguished.

Read cost claims

Big O, Ω and Θ

Operations & costs

O is an asymptotic upper bound, Ω a lower bound and Θ a tight bound. Each describes a function; specify whether that function measures worst-case, expected or another cost.

Fragment

Operations & costs · Big O, Ω and Θ
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
O(g(n)): grows no faster than a constant × g(n), eventually
Ω(g(n)): grows at least as fast as a constant × g(n), eventually
Θ(g(n)): both upper and lower bounds

Big O does not itself mean worst-case, nor Ω best-case.

Amortized versus expected cost

Operations & costs

Amortized analysis bounds total cost over a sequence of operations, without a random-input assumption. Expected cost averages under a defined probability model.

Fragment

Operations & costs · Amortized versus expected cost
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
Dynamic-array append: amortized O(1), worst-case O(n)
Hash lookup: expected O(1) under suitable hashing/load
One unlucky operation can cost more.

Neither bound is a per-operation latency guarantee.

Count the operation that actually dominates

Operations & costs

A constant number of comparisons is not constant total time when comparing arbitrarily long keys. Allocation, copying and I/O may dominate in practice.

Fragment

Operations & costs · Count the operation that actually dominates
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
Compare fixed-width integers: conventional O(1)
Compare strings of length k: worst-case O(k)
Emit k output values: at least Ω(k)

Memory/cache behavior affects elapsed time even when asymptotic bounds match.

Separate input, output and auxiliary space

Operations & costs

Auxiliary space is temporary working storage beyond the input/output conventions of the analysis. Recursion stack space counts unless explicitly excluded.

Fragment

Operations & costs · Separate input, output and auxiliary space
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
Total space = retained input + output + working storage
Recursive depth d often needs O(d) stack frames

“In place” conventions vary; state whether stack storage is included.