I know that $O(n^2\times \log(n))$ is greater than $O(n^2)$, but is $O(n^2\times \log(n))$ greater than $O(n^{2.5})$?
3 Answers
In order to compare 2 complexities just calculate a limit of their ratios as below:
$\displaystyle\begin{align*} \lim_{n\to\infty}\frac{n^2log(n)}{n^2\sqrt{n}} &= \lim_{n\to\infty}\frac{log(n)}{\sqrt{n}} = \lim_{n\to\infty}\frac{log(\sqrt{n})^2}{\sqrt{n}} = \lim_{n\to\infty}\frac{2log(\sqrt{n})}{\sqrt{n}} \\ &\underset{\left| k = \sqrt{n} \right|}{=} \ \ \lim_{k\to\infty}\frac{2log{(k)}}{k} = 2\lim_{k\to\infty}\frac{log{(k)}}{k} \\ &\leq 2\lim_{k\to\infty}\frac{ln{(k)}}{k} \\ &\overset{\ast}{=} 2\lim_{k\to\infty}\frac{(ln{(k))'}}{k'} = 2\lim_{k\to\infty}\frac{\frac{1}{k}}{1} = 2\lim_{k\to\infty}\frac{1}{k} \\ &= 0 \end{align*}$
We use L'Hôpital's rule to simplify calculating a limit for $\frac{\ln(k)}{k}$ at *.
As you can see, $O(n^2\times\log(n))$ is lower than the other.
$O(n^2 \times \log(n))$ is greater than $O(n^2)$ but it is smaller than $O(n^{2 + \epsilon})$ for any $\epsilon > 0$, however small $\epsilon$ is (see here).
In particular, it is smaller than $O(n^{2.5})$. You're basically comparing the growth of $\log$ and square root.
- 3,612
- 1
- 15
- 23
- 221
- 1
- 6
As $n^{0.5}$ is always greater than $\log(n)$, $O(n^{2.5})= O(n^2 \times n^{0.5})$ is always bigger than $O(n^2 \times \log(n))$. Anyway, you should consider your real algorithm usage scenario to choose one which fits the best.
- 3,612
- 1
- 15
- 23
- 159
- 2