简体   繁体   中英

Can O(n + log(m)) be simplified?

From my understanding, different variables are treated separately (but I might be wrong).

I know O(n + log(n)) simplifies to O(n), and O(n + m) cannot be simplified, but what about O(n + log(m))?

Thanks for any help you can give!

Big O is asymptotic, so if you have condition fe m <= 2*n you may simplify this. But without such condition you can not.

I think,

If m <= n^2 then O(n+log(m)) simplifies as O(n)

This is log base 2. Now take an example, let n = 8, now take m = 8^2 = 64 and log(64) = 6 < 8 so, The complexity will be O(n). if m = 8^3 = 512, log(512) = 9 > n, then the complexity will be O(log(m))

If there no relation between n and m, then cannot simplify O(n + log(n)).

Generally speaking, if you have any big-O of the form O(f(n, m)) where m and n are free and independent variables, there isn't a nice way to simplify the expression. That means that, say, O(m + n), O(m log n), O(log m+n n), O(m 137 + 2 n ), etc. can't be rewritten in terms of some simpler function that depends purely on m or n. The reason for this is that big-O notation measures how some quantity grows for "sufficiently large" values of the inputs, and if m and n aren't related to one another then each of m and n can grow "sufficiently large" independently of one another.

There are some cases, though, where there is some known relationship between m and n. For example, in graph algorithms, it's common to assume that m (the number of edges) is between n-1 and n 2 , representing the case where the graph is minimally connected and when the graph has the maximum possible number of edges. In those cases, you do sometimes see some simplifications made. If that relationship between m and n holds, for example, then you'll usually see O(log n) rather than O(log m) because log (n-1) ≤ m ≤ 2 log n in that case. However, even then it's uncommon to replace m with n 2 because dense and sparse graphs are different cases and the runtimes may be better predicted with a more precise runtime analysis.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM