Is $O(n \log(\log n))$ worse or better than $O(n^2)$?

887 Views Asked by At

I'm working on implementing the Sieve of Eratosthenes in C++. In doing so, I already have a function that will find all the prime numbers up to a given $N$; it does so in $O(n^2)$.

From reading some work on the Sieve of Eratosthenes, it runs in $O(n\log(\log n))$. Now given that $O(\log(\log n))$ is faster than $O(n)$ which is faster than $O(n^2)$, I would wager that: $$ O(\log(\log n)) < O(n) < O(n) * O(\log(\log n)) < O(n^2) $$

Is this the case, or is it: $$ O(\log(\log n)) < O(n) * O(\log(\log n)) < O(n) < O(n^2) $$

1

There are 1 best solutions below

0
On BEST ANSWER

$O(n \log(\log n)) < O(n\log n) < O(n^2)$

The second chain of inequalities in your answer is incorrect, because $O(n) * O(\log(\log n)) > O(n),$ since $O(\log(\log n)) > O(1)$