简体   繁体   中英

For an algorithm with a time complexity of O(N+M), if M is always less than N, can we say the time complexity will be O(N)?

Give an algorithm with time complexity of O(N+M) and M<N.

Can we conclude O(N+M) => O(N+N) => O(2N) => O(N)

Will that be correct?

f(N, M) = O(N + M) is by definition

E c, N0, M0: A N ≥ N0, M ≥ M0: f(N, M) ≤ c (N + M)

But by your hypothesis, M < N so that

E c, N0, M0: A N ≥ N0, M ≥ M0: f(N, M) ≤ c (N + M) < c 2N

and

E c', N0, M0: A N ≥ N0, M ≥ M0: f(N, M) ≤ c' 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