E.g 1: A(n) = log(2^n) + n^(1/3) + 1000 Would I be right to say that the last 2 terms can be "ignored" as they are insignificant as compared to the first? And thus the bound is O(2^n)?
If you simplify the expression, you get A(n) = n*log(2) + n^(1/3) + 1000
. The last two terms grow more slowly than the first, n*log(2)
, which is simply O(n)
. Hence A(n)
is O(n)
.
E.g 2: B(n) = n + (1/2)*n + (1/3)*n + (1/4)*n + ... + 1 I am more uncertain about this one, but I would give a guess that it would be O(n)? 1 is ignored (as per reasoning for 1000 in E.g. 1), that's what I'm sure.
This one is tricky because it involves an infinite series. If you only had n + (1/2)*n + (1/3)*n + (1/4)*n
, then it would be equivalent to a*n
with some fractional a
, and that is O(n)
. However, since the expression is a divergent infinite series known as the harmonic series, you cannot conclude that B(n)
is O(n)
. In fact, B(n)
can be simplified as S_k(1/i)*n + 1
as k tends to infinity, with S_k(1/i)
the sum of 1/i
with i
from 1
to k
. And because S_k
diverges as k tends to infinity, B(n)
also tends to infinity, assuming n>0
.
In the end, B(n)
in not bounded. It doesn't have a proper order of growth.
Edit: if B(n)
does not contain an infinite series but instead stops at (1/n)*n
, which is the last 1
in your expression, then the answer is different.
The partial sums of the harmonic series have logarithmic growth. That means that B(n)/n
, which is exactly the partial sum, up to n
, of the harmonic series, is O(log n)
. In the end, B(n)
is simply O(n log n)
.