Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which constants can be ignored in Big O for time complexity - exponential cases?

The obvious one is a constant on a linear term for example 2n, 4n and 8n are all just n or O(n).

But what about the exponential constant 1.6^n and 2^n. In this case the constant seems to have a greater effect on the time complexity.

Also there is not really a convenient way to write a catch all for exponential time complexity.

O(K^n) perhaps.

In this cheat sheet, they seem to use O(2^n) does that mean that all exponential complexities should be written that way?

Probably not.

like image 278
jennifer Avatar asked Dec 14 '25 15:12

jennifer


2 Answers

You're right that 2n, 4n and 8n are all just O(n), and you're also right that O(1.6n) is not the same as O(2n). To understand why, we need to refer to the definition of big O notation.

The notation O(...) means a set of functions. A function f(n) is in the set O(g(n)) if and only if, for some constants c and n0, we have f(n) ≤ c * g(n) whenever n ≥ n0. Given this definition:

  • The function f(n) = 8n is in the set O(n) because if we choose c = 8 and n0 = 1, we have 8n ≤ 8 * n for all n ≥ 1.
  • The function f(n) = 2n is not in the set O(1.6n), because whichever c and n0 we choose, 2n > c * 1.6n for some sufficiently large n. We can choose n > log2 c + n0 log2 1.6 for a concrete counterexample.
  • Note however that f(n) = 1.6n is in the set O(2n), because 1.6n ≤ 1 * 2n for all n ≥ 1.

For a "catch-all" way of writing exponential complexity, you can write 2O(n). This includes exponential functions with arbitrary bases, e.g. the function f(n) = 16n since this equals 24n, and 4n is in the set O(n). It's an abuse of notation, since raising the number 2 to the power of a set of functions doesn't really make sense in this context, but it is common enough to be understood.

like image 195
kaya3 Avatar answered Dec 18 '25 16:12

kaya3


That is correct. The cheat sheet you linked to here can not show all the different complexities so it picks the most common ones.

Simply put, if you have a function growing at 3 ^ n. It can not be classified as 2 ^ n because it will break the definition of Big O.

The some what complex looking math that describes Big O is simply saying that it can't ever be bigger. And also ignore linear growth constants.

f(n) ≤ c * g(n) whenever n ≥ n0
like image 26
bob Avatar answered Dec 18 '25 17:12

bob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!