Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 1.34 KB

2.3-dominance_relations.md

File metadata and controls

34 lines (22 loc) · 1.34 KB

Growth Rates and Dominance Relations

Growth rates

The growth rate of its time complexity functions can easily render an algorithm impractical even for relatively small inputs. Below are some complexity functions and the input ranges where they become unusable:

  • O(n!) ~ n > 20

  • O(2^n) ~ n > 40

  • O(n^2) ~ n > 100,000

  • O(n) and O(n lg n) ~ n > 1 bn

  • O(lg n) ~ any imaginable n

Dominance relations

  • the Big Oh notation groups functions into a set of classes.
  • functions belonging to each class are considered equal with respect to Big Oh
  • a faster-growing function class dominates a slower-growing one

Function classes

  • Constant functions, f(n) = 1, no dependence on the parameter n (e.g adding two numbers)
  • Logarithmic functions, f(n) = log n (e.g binary search)
  • Linear functions, f(n) = n (e.g looking at each item once in an n-element array)
  • Superlinear functions, f(n) = n lg n (e.g mergesort)
  • Quadratic functions, f(n) = n^2 (looking at most or all pairs in an n-element universe)
  • Cubic functions, f(n) = n3 (enumerate through all triples in an n-element universe)
  • Exponential functions, f(n) = c^n for a given constant c > 1 (e.g enumerating all subsets of n items)
  • Factorial functions, f(n) = n! (e.g all permutations or orderings of n items)

n! >> 2^n >> n^3 >> n^2 >> n lg n >> n >> lg n >> 1