Big-O notation provides a way to measure the ‘upper limit’ or the ceiling function for the running time (or storage taken) of an algorithm. Mathematically, it is similar to the asymptotic upper bound.
Formal Definition
Big-O Notation
Note
- = Growth Function
- = Initial n value for which (the ceiling function) starts to overtake
- = Scaling constant for which can overtake If the equation holds, is said to be (‘Big O of’)
Technically, can be any function. , and are all valid big-O functions, but the closest upper bound is the best option.
This definition has the implication that f but , then is always faster than .
Common Big-O Functions
(and where they are found)
- : Running time independent of input.
- : Typical for “divide and conquer” solutions, for example, lookup in a balanced search tree.
- : Linear. When each input element must be processed once.
- : Each input element processed once and processing involves other elements too, for example, sorting.
- : Quadratic, cubic. Processing all pairs (triples) of elements.
- : Exponential. Processing all subsets of elements.