O(m+n) 和 (O(max(m,n)) 一样吗? [英] Is O(m+n) the same as (O(max(m,n))?
本文介绍了O(m+n) 和 (O(max(m,n)) 一样吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有两个变量,比如 m 和 n,并且我的算法的时间复杂度为 O(m+n),那么 O(m,n) 是否与 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?
推荐答案
是的.因为 O(m+n) 总是小于 O(2(m+n)),它与 O(m+n) 仅相差一个常数因子,并且 max(m+n) <2(m+n).这只是分析它的一种方法.
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.
这篇关于O(m+n) 和 (O(max(m,n)) 一样吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文