简体   繁体   English

如果已知在所有情况下m都小于n,则O(n + m)是否等于O(n)?

[英]Is O(n+m) equal to O(n) if m is known to be less than n in all cases?

I may have the notation wrong. 我可能使用的符号有误。 I think this because are not constants ignored in big O notation? 我认为这是因为常量不能以大O表示法忽略吗? I'm pretty new to all this algorithmic analysis stuff. 我对所有这些算法分析材料都很陌生。 Any help would be greatly appreciated? 任何帮助将不胜感激?

I'm going through an array, keeping track of counts in another array and then going over that second array keeping track of running counts. 我正在遍历一个数组,在另一个数组中跟踪计数,然后在第二个数组中跟踪运行计数。

Yes. 是。 If m is always at most n , then O(n+m) is O(n+n) is O(2n) is O(n). 如果m始终最多为n ,则O(n + m)为O(n + n)为O(2n)为O(n)。

As @phs points out in the comments, this is even the case if m is at most X*n (for a fixed X ): Then O(n+m) is O(n+X*n) is O(Y*n) is O(n). 正如@phs在注释中指出的,即使m最多为X*n (对于固定X ),情况也是如此:那么O(n + m)为O(n + X * n)为O(Y * n)是O(n)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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