Asymptotic Analysis

From Notes
Jump to navigation Jump to search


All of the definitions of Big-O, Big-Ω, and Big-Θ below have something to do with existentially (∃) bound constants (generally C and n0) that make definition true. These constants are referred to in the discrete mathematics textbook as witnesses.

Definition of Dominance

Also referred to as asymptotic comparison

In general, we say f is asymptotically less than or equal to () g if and only if there exists a natural number n0 such that f(n)g(n) for all n>n0

fgn0 n(nn0f(n)g(n))

Conversely, we say g is asymptotically greater than or equal to () f.

Example

Let f(n)=5n and g(n)=n2:

  • When n<5, f(n)>g(n)
  • Asymptotically, g "grows faster" than f, so g(n)f(n) when n>5
  • Given the definition above, we can say that 5nn2


Big O

An upper bound on a function f:

f(n)O(n)f(n)Cnf(n)n
Precise Definition: f(n) is big oh of g(n) if and only if there exists a constant C and a natural number n0 such that |f(n)|C|g(n)| for all n>n0
f(n)O(g(n))C n0 n(nn0|f(n)|C|g(n)|)

Common Order of Dominance

  1. O(nn) exponential
  2. O(n!) factorial
  3. O(n2) polynomial
  4. O(nlogn)
  5. O(n) linear
  6. O(n)
  7. O(logn) logarithmic
  8. O(1) constant


Big Ω

A lower bound on a function f [1]:

f(n)Ω(n)f(n)Cnf(n)n
Precise Definition: f(n) is big omega of g(n) if and only if there exists a constant C and a natural number n0 such that |f(n)|C|g(n)| for all n>n0
f(n)Ω(g(n))C n0 n(nn0|f(n)|C|g(n)|)
Note: f(n)=Ω(g(n))g(n)=O(f(n))


Big Θ

Means that function has same asymptotic growth as another function up to multiplication by constants. Similar to squeeze theorem in Calculus for proof of convergence.

f(n)Θ(g(n)) L<(limn|f(n)||g(n)|=L)
Precise Definiton: f(n) is big theta (same order) of g(n) if and only if there exists constants L and U and a natural number n0 such that |f(n)| is betweenL|g(n)| and U|g(n)| for all n>n0.
f(n)Θ(g(n))L,U n0 n(nn0L|g(n)||f(n)|U|g(n)|)

In other words,

f(n)Θ(g(n))(f(n)O(g(n))f(n)Ω(g(n)))

In this case, n0 for Big-Θ takes the larger value of the n0's used in Big-O and Big-Ω.


Examples

Example 1

  • Claim 5n=O(n2)
  • Choose witnesses C=5 and n0=1 (can be derived mathematically to fit the form of the definition of Big-O: |5n|5|n2| for all n1)
  • {5n<5n2|5n|5|n2|} true  n1


Example 2

When Joe implements algorithm A in Java and runs it on his home PC. Running time is

f1(n)=7n+52

When Sue implements algorithm A in Fortran and runs it on dilbert.cs.tamu.edu, the running time is

f2(n)=2n+25

Resulting speed of both algorithms is O(n)


Example 3

7n2+6n+2=O(n2)n33n+2=O(n3)(7n2+6n+2)(n33n+2)=O(n2n3)=O(n5)


Example 4

(See Wikipedia:Binomial coefficient→)

(n2)=n(n1)2=n22n2=n22+O(n)=O(n2)

Footnotes

  1. comparison-based sorting algorithms need at least Ω(nlogn) comparisons.