学习考试并得到这个问题:
Comparing two algorithms with asymptotic complexities O(n) and O(n + log(n)),
which one of the following is true?
A) O(n + log(n)) dominates O(n)
B) O(n) dominates O(n + log(n))
C) Neither algorithm dominates the other.
O(n)支配log(n)正确吗?那么在这个问题上,我们只从两者中取o(n)并推导出既不支配?
答案 0 :(得分:3)
[C]是真的,因为 Big-O <{em>
的the summation propertySummation O(f(n)) + O(g(n)) -> O(max(f(n), g(n))) For example: O(n^2) + O(n) = O(n^2)
在 Big-O 中,您只关心增长最快的功能而忽略所有其他添加剂。
编辑:最初我把[A]作为答案,我只是没有太多关注所有选项并误解了[A]选项。这是更正式的证明
O(n) ~ O(n + log(n)) <=>
O(n) ~ O(n) + O(log(n)) <=>
O(n) ~ O(n).
答案 1 :(得分:1)
是的,这是正确的。如果运行时是几个运行时的总和,按数量级,最大数量级占主导地位。
答案 2 :(得分:1)
假设在asymptotic tight bound
的意义上使用了大O符号,它应该用大-Theta表示,那么我会回答C),因为Theta(n) = Theta(n + log(n))
。 (因为log(n)
由n
支配。
如果我正式(数学上)正确,那么我会说这些答案都不正确,因为O(n)
和O(n+log(n))
只给出上界,但不是渐近行为的下界:
允许f(n) in O(n)
和g(n) in O(n + log(n))
。然后是以下反对的例子:
对于A):f(n) = n
中的O(n)
和g(n) = 1
中的O(n + log(n))
。然后g(n)
不支配f(n)
。
表示B):f(n) = 1
中的O(n)
和g(n) = n
中的O(n + log(n))
。然后f(n)
不支配g(n)
。
表示C):f(n) = 1
中的O(n)
和g(n) = n
中的O(n + log(n))
。然后g(n)
确实支配f(n)
。
因为这将是一个非常棘手的问题,我假设您使用更常见的草率定义,这将给出答案C)。 (但您可能想要检查big-O
)的定义。
如果我的回答让你感到困惑,那么你可能没有使用正式的定义,你可能应该忽略我的答案......