There are basically three kinds of time complexity notation:

  1. - Upper bound
  2. - Lower bound
  3. - Tight bound There are categorically two types of time complexity:
  4. Polynomial Time complexity i.e.
  5. Exponential Time complexity i.e. A more deep look into them:

Big-O Notation () - Upper Bound

  • Definition: means that grows at most as fast as up to a constant factor, for sufficiently large .
  • Mathematically: There exist positive constants and such that for all .

Example: Suppose . We claim that .

To prove this:

  1. For large , the term dominates the and constant terms.
  2. We can find constants and such that . Let’s choose and see if it works for .

for

Since and for , our choice of and works.

Thus, means that for sufficiently large , will never grow faster than some constant multiple of .

Big-Omega Notation () - Lower Bound

  • Definition: means that grows at least as fast as up to a constant factor, for sufficiently large .
  • Mathematically: There exist positive constants and such that for all .

Example: Suppose . We claim that .

To prove this:

  1. For large , the term dominates the and constant terms.
  2. We can find constants and such that . Let’s choose and .

for

Since , our choice of and works.

Thus, means that for sufficiently large , will always grow at least as fast as some constant multiple of .

Theta Notation () - Tight Bound

  • Definition: means that grows exactly as fast as up to constant factors, for sufficiently large . It provides both an upper and lower bound.
  • Mathematically: There exist positive constants , , and such that for all .

Example: Suppose . We claim that .

To prove this:

  1. For large , the term dominates the and constant terms.

We need to show both:

  • for some .
  • for some .

From the previous parts:

  • with .
  • with .

So, for : for

Thus, means that for sufficiently large , grows at the same rate as up to constant factors.

Summary

  • Big-O (): Describes an upper bound. means grows no faster than .
  • Big-Omega (): Describes a lower bound. means grows at least as fast as .
  • Theta (): Describes a tight bound. means grows exactly as fast as , both in upper and lower bounds.

Example

Fibonacci Number with approach:

int fib_expo(int n) {
	if (n <= 1){
		return n;
	}
	return fib_expo(n-1) + fib_expo(n-2);
}

Fibonacci Number with approach:

vector<int>saved(100, -1);
int fib_linear(int n){
	if (saved[n] != -1){
		return saved[n];
	}
	if (n <= 1){
		saved[n] = n;
	} else {
		saved[n] = fib_linear(n-1) + fib_linear(n-2)
	}
	return saved[n];
}