[Math] Finding Big-O with logarithmic functions

algorithmsdiscrete mathematicslogic

Give a big-O estimate for,

$$ (nlog(n) +1)^{2} + (log(n) +1)(n^2 +1)$$

my attempt was:

  • separate the function

  • find the dominant values

  • and take the big-O evaluation

This is what I got:

first seperation

$$(nlog(n)+1)^2 $$
$$ \rightarrow (nlog(n))^2 $$
$$ \rightarrow (nlog(n)) ^2 = O(n^2)^2 = O(n^4)$$

second seperation

$$(log(n) +1)(n^2 +1)$$
$$ \rightarrow log(n)(n^2) $$
$$ \rightarrow n^2(log(n)) = O(n^2(log(n))) $$

Now there is a theorem that states: when we are adding two functions, the big-O estimate for the sum of both functions is the largest big-O estimate from either function:

in our case $n^4$ is a bigger big-O estimate than $n^2(log(n)) $

Therefore:

$$ (nlog(n) +1)^{2} + (log(n) +1)(n^2 +1) = O(n^4)$$

But, this is the wrong answer according to the textbook…

Best Answer

First term: $(n \log n + 1)^2 = (n^2 (\log n)^2 + 2 n \log n + 1) = O(n^2 (\log n)^2)$

Second term: $(\log n + 1)(n^2 + 1) = (n^2 \log n + n^2 + \log n + 1) = O(n^2 \log n)$

Now, add two terms and apply the rule for sum of two functions that you have mentioned. You should get $O(n^2 (\log n)^2)$