Big o 算法控制

Big o 算法控制,big-o,asymptotic-complexity,Big O,Asymptotic Complexity,学习考试并获得以下问题: 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)对吗

学习考试并获得以下问题:

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)并推断出两者都不占支配地位?

是的,这是正确的。如果运行时是几个运行时的总和,按数量级,最大数量级占主导地位。

[C]是真的,因为大O

总和 O(f(n))+O(g(n))->O(max(f(n),g(n))) 例如: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).
O(n)~O(n+log(n))
O(n)~O(n)+O(log(n))
O(n)~O(n)。

假设在
渐近紧界
的意义上使用大-O符号,它确实应该用大θ表示,那么我会回答C),因为
θ(n)=θ(n+log(n))
。(因为
log(n)
n
控制)

如果我在形式上(数学上)是正确的,那么我会说这些答案中没有一个是正确的,因为
O(n)
O(n+log(n))
只给出了渐近行为的上界,而不是下界:

设O(n)中的
f(n)
和O(n+log(n))中的
g(n))
。然后有以下相反的例子:

对于A):让
f(n)=n
in
O(n)
g(n)=1
in
O(n+log(n))
。那么
g(n)
并不支配
f(n)

对于B):让
f(n)=1
in
O(n)
g(n)=n
in
O(n+log(n))
。那么
f(n)
并不支配
g(n)

对于C):让
f(n)=1
in
O(n)
g(n)=n
in
O(n+log(n))
。那么
g(n)
确实支配了
f(n)

由于这将是一个非常棘手的问题,我假设您使用更常见的草率定义,这将给出答案C)。(但您可能需要检查定义中的
big-O


如果我的回答让你困惑,那么你可能没有使用正式的定义,你可能应该忽略我的回答…

C是正确的,因为如果你所说的原因
O(n) ~ O(n + log(n))      <=>
O(n) ~ O(n) + O(log(n))   <=>
O(n) ~ O(n).