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.