1

Does $n\log n = O(n \log n + n)$ hold?

I don't think it does trivially because I think as $n$ grows larger, $n\log n$ will converge to one value, and as the $+ n$ grows, $n\log n + n$. But I am uneasy about my initial thoughts about this. For example, mergesorting a list and then iterating through each element to compare for the smallest difference would result in a running time of $O(n\log n+n)$, yet mergesort is $O(n\log n)$.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
Pablo
  • 11
  • 1

1 Answers1

2

I'm not sure what do you mean that "$n \log n$ will converge to one value" because in fact $\log n$ diverges to infinity (so is $n \log n$).

Recall that $f(n) \in O(g(n))$ iff exists constants $c, N$ so that $f(n) \leq c \, g(n)$ for every $n \geq N$ (intuitively, $f(n)$ could be bound above by a constant multiple of $g(n)$ as $n$ grows large enough).

$n \log n \in O(n \log n + n)$ is then obviously true since $n \log n + n > n \log n$.

It is worth noting that the other side $n \log n + n \in O(n \log n)$ also holds because $n \leq n \log n$ as $n \geq \mathrm{e}$, so choosing $(c, N) = (2, \mathrm{e})$ proves this.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
meteor
  • 21
  • 1