Asymptotic Notation and Growth of Functions
Algorithms · Advanced Placement
Asymptotic Notation and Growth of Functions: the big picture
Asymptotic notation describes how a function behaves as its argument grows without bound, discarding constant factors and lower-order terms that depend on implementation details rather than on the algorithm. Big O provides an asymptotic upper bound: a function is in big O of another if beyond some threshold it is bounded above by a constant multiple of that other function. Big Omega provides the corresponding lower bound, and Theta provides a tight bound, holding when both the upper and lower bounds apply, which is the notation that should be used whenever it is available because it conveys the most information. Little o and little omega express strict bounds, where the ratio tends to zero or to infinity rather than being bounded. The notation is used in equations and inequalities with a specific meaning, standing for some anonymous function satisfying the stated bound, which is why statements involving it are read left to right and not as symmetric equalities. The standard growth hierarchy runs from constant through logarithmic, polylogarithmic, linear, linearithmic, polynomial, exponential and factorial, and comparing two expressions usually reduces to applying the limit of their ratio or to taking logarithms. Stirling's approximation handles factorials, and summation formulae and bounds handle the series that arise from loop analysis.
Big O, Theta, Omega & the Growth Hierarchy
Asymptotic notation throws away exactly the things that depend on your compiler and keeps what depends on your algorithm. Big O is an upper bound, Omega a lower bound, and Theta a tight bound — and you should state Theta whenever you can, because it says strictly more. The most common error is treating big O as if it were tight: saying an algorithm is O(n²) is true of a linear algorithm too, so it conveys less than people usually intend. Comparing growth rates almost always reduces to taking a limit of the ratio or taking logarithms.
{{illustration:algos-l02-f1}}
{{illustration:algos-l02-f2}}
Key relations
- The asymptotic definitions. f = O(g) ⇔ ∃ c, n₀: f(n) ≤ cg(n) ∀ n ≥ n₀ ; f = Θ(g) ⇔ f = O(g) and f = Ω(g)
Summations, Stirling's Approximation & Bounding Series
Loop analysis produces sums, so bounding sums is a working skill rather than a formality. The arithmetic series gives the quadratic bound on insertion sort's comparisons; the geometric series is bounded by a constant times its largest term when the ratio is below one, which is why halving recursions cost a constant factor; and the harmonic series grows logarithmically, which is where the log factor in quicksort's average case comes from. Stirling's approximation handles factorials, and it is what turns the information-theoretic lower bound on comparison sorting into n log n.
{{illustration:algos-l02-f3}}
{{illustration:algos-l02-f4}}
Key relations
- Key summation results. ∑ₖ₌₁ⁿ k = (n(n+1))/2 ; ∑ₖ₌₀^(∞) r^k = 1/(1−r) ; n! ≈ √(2π n)(n/e)ⁿ