Theory ofIntelligence
Index
Algorithms & Data StructuresBook Index: Letter B

Big-O Notation and Time Complexity

Mathematical notation describing the asymptotic upper bound of an algorithm's runtime as input size approaches infinity.

functionsMathematical Representation
f(n)=O(g(n))  ⟺  ∃c>0,n0>0:∣f(n)∣≤c∣g(n)∣  ∀n≥n0f(n) = O(g(n)) \iff \exists c > 0, n_0 > 0 : |f(n)| \le c|g(n)| \; \forall n \ge n_0

Why Big-O Matters

In computer science, comparing runtime in milliseconds is unreliable because hardware speeds differ. Big-O notation characterizes the fundamental scaling behavior of an algorithm independent of hardware:

NotationNameTypical Example
O(1)O(1)Constant TimeHash table lookup
O(log⁡n)O(\log n)Logarithmic TimeBinary search
O(n)O(n)Linear TimeLinear array traversal
O(nlog⁡n)O(n \log n)Linearithmic TimeMerge Sort / Quick Sort
O(n2)O(n^2)Quadratic TimeNested loops / Bubble sort
O(2n)O(2^n)Exponential TimeRecursive Fibonacci