math rules when having 2 variables in Big-O

52 Views Asked by At

I came across the following in some lecture notes:

O(log n) + O(log m) = O(log n + log m ) = O(log (m + n))

that last step to O(log(m+n)) seems weird to me because O(log(m+n)) grows slower than O(log n + log m ).

The logarithm rules certainly tell that log(n) + log(m) is log(n.m), though is the above given in the lecture notes, valid under Big-O ?

2

There are 2 best solutions below

0
On BEST ANSWER

Indeed, $\color{red}{O(\log(m+n))=O(\log(n) + \log(m))}$, since, for every $m\geqslant2$ and $n\geqslant2$, $$m+n\leqslant m\cdot n\leqslant(m+n)^2, $$ hence $$ \log(m+n)\leqslant\log(m)+\log(n)\leqslant2\cdot\log(m+n).$$

0
On

It's crucial to note that big-O notation describes the limiting behaviour as $n,m\to\infty$. In this limit, $\log(n)+\log(m)$ and $\log(n+m)$ behave identically so it's perfectly consistent.