3

I'm wondering if an algorithm with an exponential worst time complexity, should always have that stated as O(2^n). For example, if I had an algorithm that's operations triple for each addition to the input size, would I write it's time complexity as O(3^n), or would it still be classified as O(2^n).

Any formal explanation would be greatly appreciated.

Carlos
  • 5,991
  • 6
  • 43
  • 82
  • `3^n` is the same as `2^(log3 * n)`. So `3^n` is the same complexity as `2^m` where `m=log3*n`. – CoronA Aug 09 '20 at 14:47
  • 1
    Go back to the definition: is there a constant `C` such that `3^n <= C*2^n` for all sufficiently large `n`? Drawing a graph of `3^n / 2^n` should suggest the answer pretty clearly, and a mathematical proof is not much harder. – Nate Eldredge Aug 09 '20 at 14:56

2 Answers2

6
3^n != O(2^n).

Let us assume that it were true. Then there exists constants c and n0 such that 3^n ≤ c * 2^n for all n ≥ n0.

The last requirement is equivalent to (3/2)^n ≤ c for all n ≥ n0.

However, (3/2)^n → ∞ as n → ∞, so (3/2)^n ≤ c cannot be true for all n ≥ n0 for any constant c.

Jasmeet
  • 1,315
  • 11
  • 23
2

No, O(2^n) and O(3^n) are different. If 3^n were O(2^n), there'd be a constant k such that 3^n <= k * 2^n for all large n. There's no such k because 3^n / 2^n is (3/2)^n which grows arbitrarily large.

Paul Hankin
  • 54,811
  • 11
  • 92
  • 118