问题描述
我目前正在上算法课,我们正在介绍Big O表示法等。上次,我们讨论了
I'm currently taking an algorithm class, and we're covering Big O notations and such. Last time, we talked about how
O (n^2 + 3n + 5) = O(n^2)
我想知道,是否有相同的规则适用于此:
And I was wondering, if the same rules apply to this:
O(n^2) + O(3n) + O(5) = O(n^2)
另外,以下符号是否成立?
Also, do the following notations hold ?
O(n^2) + n
或
O(n^2) + Θ (3n+5)
后面的n在O之外,所以我不确定它的含义。在第二种表示法中,我添加了O和Θ。
The later n is outside of O, so I'm not sure what it should mean. And in the second notation, I'm adding O and Θ .
推荐答案
至少出于实际目的,(因此其符号具有吸引力)。 ,例如:
At least for practical purposes, the Landau O(...)
can be viewed as a function (hence the appeal of its notation). This function has properties for standard operations, for example:
O(f(x)) + O(g(x)) = O(f(x) + g(x))
O(f(x)) * O(g(x)) = O(f(x) * g(x))
O(k*f(x)) = O(f(x))
用于定义明确的函数 f(x)
和 g(x)
,以及一些常数 k
。
for well defined functions f(x)
and g(x)
, and some constant k
.
因此,对于您的示例,
是: O(n ^ 2)+ O(3n)+ O(5)= O(n ^ 2 )
和:
O(n ^ 2)+ n = O(n ^ 2)+ O(n) = O(n ^ 2)
,
O(n ^ 2)+Θ(3n + 5)= O(n ^ 2)+ O (3n + 5)= O(n ^ 2)
这篇关于您可以使用Big O表示法进行加法/乘法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!