What is the big-O of the function $2\log(\log(n)) + 3n\log(n) + 5\log(n)$?
Is it just $O(n\log(n))$ for the whole function? I'm not sure how to represent $2\log(\log(n))$.
- 41
- 1
- 1
- 2
5 Answers
Starting with an analytical assessment of the function's terms, we'll first format all terms as similarly as possible to each other, in order to more easily compare with one another. To do so, all constant factors will be removed, leaving only the variable elements of each term. This is acceptable to do since we're ultimately seeking Big-$O$ classification, which typically sets all constants within its expression to a value of $1$.
- $2\log(\log(n)) \to \log(\log(n))$
- $3n\log(n) \to n\log(n)$
- $5\log(n) \to \log(n)$
Rewriting,
$\quad f(n) \to \log(\log(n)) + n\log(n) + \log(n)$,
where $n \in \mathbb{N}.$
Now, since each term varies only by their logarithmic arguments, we can establish an inequality by direct comparison of those arguments, resulting in
$\quad \log(\log(n)) \lt \log(n) \lt n \log(n),\ \forall n \gt 1$
Therefore, it follows that
$\quad f(n) \in O(n\log(n))$
- 39,205
- 4
- 34
- 93
Please note that "the big-O of the function" isn't a correct formulation. We assume $\log$ is the binary logarithm $\log_2$. But actually the proof can be extended to any base.
We have
$$\log(x)\lt x, \forall x>0$$ and, if we plug in $\log(n)$ for $x$ $$\log(\log(n))\lt \log(n).\tag 1$$
Recall the definition of $f(n)=O(g(n))$: $$|f(n)|\le M |g(n)|,\forall n\ge n_0$$ for appropriate $M$ and $n_0$.
So if we choose $f(n)=\log(\log(n))$, $g(n)=\log(n)$, $M=1$ ,$n_0=2$
we see that $(1)$ is $$\log(\log(n))=O(\log(n))$$ and of course $$\log(\log(n))=O(n\log(n)).$$ So all three function in your expressions are $O(n\log(n))$ and therefore every linear combination of them $$a\log(\log(n)) + b \, n\log(n) + c\log(n), \quad a,b,c \in \mathrm R$$ is $O(n\log(n))$.
- 552
- 2
- 16
It is obvious that $\log n\le an$ for some constant $a$ because the number of digits of $n$ cannot exceed $n$. Then substituting $n$ for $\log n$, $\log\log n\le a\log n$. (For the base-2 logarithm, $a=1$ works.)
Combining, we have
$$2\log\log n+3n\log n+5\log n\le (2a+3n+5)\log n\le cn\log n$$ because for $n\ge1$ and $c=2a+5+3$,
$$\frac{2a+5}n+3\le c.$$
Yes, the expression is $O(n \log n)$. For large $n$, $n \log n$ dominates $\log n$ and $\log \log n$.
- 1,388
- 7
- 10
The best way to find big-o of a function like this:
$$f(n) = \sum_{i=1}^k f_i(n)$$
is to find an i where:
$$\forall j \in [1,k], j\neq i \rightarrow \lim_{n->\infty} \frac{f_j(n)}{f_i(n)} =0$$
therefor big-o is $$n\log(n)$$
- 101
- 3
