简体   繁体   中英

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? 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).

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).

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