I am confused between $n^3\log n$ and $n^3$. Normally $n\log n$ is better than $n^3$ but what's about $n^3\log n$
Asked
Active
Viewed 33 times
0
-
I'm confused about the time complexity! and the case are n^3logn and n^3, and my confusion is which one is the best – Fahim Rayhan Jul 11 '21 at 10:49
-
It is true that $n^3 \log n > n^3$ for $n > 2$ since $\log$ is an increasing function and $\log 2 = 1$ (I'm assuming that binary logarithms are involved here). That said it's impossible to say which of the two is "better" if you don't tell us what "better" means to you in this context... For some $n>2$ I'd prefer to have $n^3 \log n$ euros in my bank account rather than $n^3$ euros, however If we are talking about cans of Surströmming to eat then I'd prefer $n^3$ over $n^3 \log n$. – Steven Jul 11 '21 at 10:51
-
Even in the context of time complexity we still cannot tell you which one is "best" if we don't know what your preference is. $n^3 \log n$ grows asymptotically faster than $n^3$. Now pick whichever function you prefer... Usually people tend to prefer smaller time complexity, so that's probably what you want... – Steven Jul 11 '21 at 10:52
-
Thank you so much for your explanation. – Fahim Rayhan Jul 11 '21 at 10:55
-
Usually when talking about complexity you are comparing $O(n^3)$ and $O(n^3 \log n)$. Note that those are upper bounds, they might not be tight. I.e,, $300 n^2 = O(n^3)$ and also $3 n = O(n^3 \log n)$. Also, the $O(\cdot)$ swallows a multiplicative constant, which might make all the difference for "practical" values of $n$. So $n^3 \log n < 100 n^3$ as long as $n < 2^{100}$ (binary logarithms understood). – vonbrand Jul 12 '21 at 00:27