Time Complexity

Big-O Complexity Chart

Big-O ($O$)

Definition

  • f(n) = $O$(g(n)) iff $\exists$ c, n0 > 0 such that f(n)$\le$ c $\cdot$ g(n) $\forall$ n $\ge$ n0

Examples

  • 3n+2 = $O$(n)
    When c=4, n0 = 2, 3n+2 $\le$ 4n for all n $\ge$ 2.
  • 100n+6 = $O$(n)
    When c=101, n0 = 6, 100n+6 $\le$ 101n for all n $\ge$ 6.
  • 10n2+4n+2 = $O$(n2)
    When c=11, n0 = 5, 10n2+4n+2 $\le$ 11n2 for all n $\ge$ 5.
  • Properties

    • f(n) = $O$(g(n)) states that $O$(g(n)) is an upper bound of f(n), so n = $O$(n) = $O$(n2.5) = $O$(n3) = $O$(nn). However, we want g(n) as small as possible .
    • Big-O refers to worst-case running time of a program.

Big-Omega($\Omega$)

Definition

  • f(n) = $\Omega$(g(n)) iff $\exists$ c, n0 > 0 such that f(n)$\ge$ c $\cdot$ g(n) $\forall$ n $\ge$ n0 .

Examples

  • 3n+2 = $\Omega$(n)
    When c=3, n0 = 1, 3n+2 $\ge$ 3n $\forall$ n $\ge$ 1.
  • 100n+6 = $\Omega$(n)
    When c=100, n0 = 1, 100n+6 $\ge$ 100n $\forall$ n $\ge$ 1.
  • 10n2+4n+2 = $\Omega$(n2)
    When c=1, n0 = 1, 10n2+4n+2 $\ge$ n2 $\forall$ n $\ge$ 1.

Properties

  • f(n) = $\Omega$(g(n)) states that $\Omega$(g(n)) is a lower bound of f(n).
  • $\Omega$ refers to best-case running time of a program.

Big-Theta($\theta$)

Definition

  • f(n) = $\theta$(g(n)) iff f(n) = $O$(g(n)) and f(n) = $\Omega$(g(n)).

Examples

  • 3n+2 = $\theta$(n)
  • 100n+6 = $\theta$(n)
  • 10n2+4n+2 = $\theta$(n2)

Properties

  • f(n) = $\theta$(g(n)) states that $\theta$(g(n)) is a tight bound of f(n).
  • $\theta$ refers to average-case running time of a program.

Cheat Sheets

Data Structure Operations
Array Sorting

參考資料


Time Complexity
https://933yee.github.io/notes/2023/01/17/time-complexity/
Author
Kevin Lee
Posted on
January 17, 2023
Licensed under