Re: how is O(logm+logn) = O(log(m+n))? O is big oh.
You expected O(log(M)+log(N)) to be equivalent to O(log(M*N)) right?
It's true that log(M)+log(N) can be algebraically manipulated into log(M*N) but Big-O is not an algebra, it's a notation.
O(log(M)+log(N)) expresses that the algorithm reacts logarithmically to M as well as to N. Regardless of which you vary or both, the algorithm will respond logarithmically. So the overall complexity is logarithmic and this is also expressed by O(log(M+N)). When M and N varies the overall response is logarithmic.
Lets say that M and N varies together. Then you can replace M with N. In the first case you get
O(log(N) + log(N)) = O(2*logN) = O(logN)
And in the second case you have
O(log(N + N)) = O(log(2*N)) = O(log(N))
In Big-O both O(2*logN) and O(log(2*N)) expresses the same overall complexity, namely O(log(N)). You can multiply N with any constant, in Big-O notation it's still N. And you can multiply log(N) with any constant, it's still log(N).
So Big-O notation characterizes algorithms in terms of broad complexity classes. In this case it says, this algorithm responds logarithmically to input so it's O(log(N)). It doesn't bother with different shades of logaritmicality. Logarithmic is logarithmic is logarithmic.
Last edited by nuzzle; January 23rd, 2010 at 07:19 AM.
Bookmarks