Mohit Ashliya
Mohit Ashliya

Reputation: 635

Which time-complexity is better O(logM + logN) or O(logM.logN)?

I tried the binary search on the 2D matrix and I got the solution which gives the time compexity to be the O(logN.logM). There exist already a solution which performs it in log(MN) time. I Only want to know which is better or less-time taking. Really a burning question.

Upvotes: 1

Views: 1845

Answers (1)

Dakrin
Dakrin

Reputation: 39

Well the question is some what ambigous. If you want to ask if O(logM+logN) > O(logM*logN) then the answer is no, O(logM+logN) is always less than O(logM*logN). In the body of the question you say that your complexity is O(logN*logM) and the complexity of a known algorithm is O(log(MN)). Since O(log(MN)) = O(log(M)+log(N)) we can say that O(log(M)*log(N)) > O(log(MN))

Upvotes: 3

Related Questions