Formal Definition

Big-O Notation

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.