As tight as possible means finding a function g(n)
with smallest order of growth such that it still satisfies f(n) = O(g(n))
. In your example it is relatively straightforward (hence your confusion, I believe) - just remove everything but the fastest growing term (2^n
).
However let's consider an example where the tightest bound might not be immediately obvious - the Fibonacci sequence generator: f(n) = f(n - 1) + f(n - 2)
. A simple way to find an upper bound would be to make an approximation, by replacing n - 2
with n - 1
to give f(n) ≈ 2 * f(n - 1)
, which is O(2^n)
. This is not the tightest bound though - by solving a quadratic equation you will find that the tightest bound is in fact Ө(1.61...^n)
- see this page for more details.