Big O Notation
Formal definition
means there exist constants and such that:
In plain English: is bounded above by some constant multiple of for all sufficiently large n.
What Big O captures
The notation abstracts away details that do not affect asymptotic growth:
- Constant factors: will beat in the long run. Constants depend on hardware, OS, and language — ignoring them makes comparisons broadly valid.
- Insignificant terms: If cost is , the term eventually dominates. The term is bigger for , but overtakes it.
- Small values of n: The role of in the definition is to ignore finitely many exceptions where the bound does not hold.
Simple facts
Constant factors and insignificant terms disappear:
For the last one: for , so we can double the constant factor and drop the lower-order terms.
Containment relationships
If and are constants with , then:
The notation means that if a function is , it is also — the former gives a tighter bound. For example, if then trivially , but the converse does not hold.
Why constant factors are ignored
- They seldom make a difference asymptotically: beats for large n
- They are unstable: different hardware, operating system, or language changes them
- Ignoring them allows comparisons that remain valid across many circumstances
Limitations of Big O
Even ignoring constant factors, measurement units matter. Multiplication may be treated as one unit of cost, but multiplying two n-digit numbers for large n is itself expensive (relevant for cryptography). Few things are truly O(1): storing the number n requires O(log n) bits. An O(1) cost usually assumes operations fit within standard hardware arithmetic capacity.