Neri-kun
Neri-kun

Reputation: 193

Is O(m+n) the same as (O(max(m,n))?

If I have two variables,say m and n,and my algorithm has time complexity O(m+n),is O(m,n) the same as having O(max(m,n))?If yes,can you explain why?

Upvotes: 0

Views: 445

Answers (1)

GaryO
GaryO

Reputation: 6338

Yes. Because O(m+n) is always smaller than O(2(m+n)), which only differs by a constant factor from O(m+n), and max(m+n) < 2(m+n). That's just one way to analyze it.

Upvotes: 2

Related Questions