prove $n$ is $O(n\log n)$

7.1k Views Asked by At

In order to prove that $n$ is $O(n\log n)$, as per my understanding if we have to say $f(n)$ is $O(g(n))$ then $\lim\limits_{n \to \infty} \frac{f(n)}{g(n)}= C$

Then in that case when I am taking the limit $\lim\limits_{n\to\infty} \frac{n}{n\log n}= \frac{1}{1+\log n}$

This is not a constant but when I do trial and error I am getting $C$ and $n_0$ as $1$ and $2$

Where exactly I am doing wrong can someone please help me

Regards, Siddartha

4

There are 4 best solutions below

0
On

Taking the limit,

$$\lim_{n \to \infty} \frac{n}{n\log(n)} = \lim_{n \to \infty} \frac{1}{\log(n)}= 0$$ which is a constant, thus $n$ is $\mathcal{O}(n\log(n))$.

EDIT: If you want to use the more traditional definition (i.e. finding a $c$ and $x_0$ such that for all $x \geq x_0$, $x \leq c \cdot x\log(x)$.) If we pick $c=1$ and $x_0 = 10$, then for all $x \geq x_0 = 10$, we have $\log(x) \geq \log(10) = 1$, thus, $$x = x \cdot 1 \leq x \cdot \log(x) = 1\cdot x\log(x) = c\cdot x\log(x).$$

Thus, we have found a $x_0$ and $c$ that satisfies the definition, so $n$ is $\mathcal{O}(n\log(n))$.

2
On

It is not true that if $f$ is $O(g)$ then $\lim_{n\to\infty} \frac{f(n)}{g(n)} = C$ for some $C$. Consider for example the function $\sin$ which is in $O(1)$, simply because for all $n$ we have $\sin(n)\leq 1$, yet the limit $\lim_{n\to\infty} \frac{sin(n)}{1}$ fails to exist.

Now, in your case the limit does exist: we have $\lim \frac{n}{n\log n} = \lim \frac1{\log n} = 0$, and therefore $n\in O(n\log n)$.

1
On

you have the wrong operator here. it can not be = as $f(x)=O(g(x))$ says "$f$ does not grow faster than $g$". So you might not be able to find a constant. The right definition is

$$\limsup_n \frac{f(n)}{g(n)} < \infty$$

0
On

$f(n) \in O(g(n))$ provided that there exist $M>0, x \in \Bbb{R}$ such that whenever $m>x$ we have $|f(m)| < M|g(m)|$. In other words, $|f|$ is eventually bounded above by some constant multiple of $|g|$. For example, if $f(n)=n$ and $g(n) = n\log(n)$, we can let $M = 1$ and $x = 2$; then we have that whenever $n > 2$, $n \leq n\log(n)$, and so $n\in O(n\log(n))$.

(assuming $\log$ is base $2$)