I have noticed that big-O of 1000n or 10n is the same thing as O(n), but big-O of 2^n and 3^n are different: O(2^n) and O(3^n), what I don't get is why can't we ignore the constants in this case (2 or 3) and whether there is any mathematical proof justifying this?
O(C^n) — Exponential: The number of steps it takes to accomplish a task is a constant to the n power (pretty large number).
Exponential: O(2^N) For instance, with a function whose step-time doubles with each subsequent step, it is said to have a complexity of O(2^N). A function whose step-time triples with each iteration is said to have a complexity of O(3^N) and so on.
Formal Definition: f(n) = O(g(n)) means there are positive constants c and k, such that 0 ≤ f(n) ≤ cg(n) for all n ≥ k. The values of c and k must be fixed for the function f and must not depend on n. Also known as O, asymptotic upper bound.
Because there is no constant value of k
that satisfies the inequality 3^n <= k * 2^n
for arbitrarily large n
. Thus f(n) = 3^n
is not a member of O(2^n)
.
See http://en.wikipedia.org/wiki/Big_O_notation#Family_of_Bachmann.E2.80.93Landau_notations.
Eventhough for the original asker this might not be of use anymore,
I think it can be approached in an easier way.
Basic defenition of O-notation: iff f(g) would be in O(g(n)),
then there exist a rational number c, for which it holds that f(g) = c * g(n), for n >= n0
(n0 being a number that you pick yourself)
Let's try to apply this for 3^n in O(2^n)
3^n = 2^n * c
3^n = 2^n * (3^n / 2^n)
3^n = 2^n * (3/2)^n
3^n = 2^n * 1.5^n
this means that c = 1.5^n which is not a rational number, but an exponential function on its own.
On the other hand, following the same for 3^n in O(2^n), we would get 2^n <= 3^n * (2/3)^n
This might seem like a conflict, until you realise that 0.75^n < 1 for all n > 0, which means that if you take any c > 1, it will be larger than 0.67^n from n = 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With