对Big-O表示法感到困惑

对Big-O表示法感到困惑,big-o,asymptotic-complexity,Big O,Asymptotic Complexity,我不熟悉大O符号。阅读时,我遇到了一个例子: Qus : Find upper bound for f(n) = n^2 + 1 Sol : n^2 + 1 <= 2n^2 for all n >= 1 so f(n) = O(n^2) with c = 2 and n0 = 1 Qus : Find upper bound for f(n) = n Sol : n <= n^2 for all n >=1 so f(n) = O(n^2) with c =

我不熟悉大O符号。阅读时,我遇到了一个例子:

Qus : Find upper bound for f(n) = n^2 + 1

Sol : n^2 + 1 <= 2n^2  for all n >= 1

so f(n) = O(n^2) with c = 2 and n0 = 1
Qus : Find upper bound for f(n) = n

Sol : n <= n^2 for all n >=1

so f(n) = O(n^2) with c = 1 and n0 = 1
求f(n)=n^2+1的上界 溶胶:n^2+1=1 所以f(n)=O(n^2),其中c=2,n0=1 在此之后,我遇到了第二个例子:

Qus : Find upper bound for f(n) = n^2 + 1

Sol : n^2 + 1 <= 2n^2  for all n >= 1

so f(n) = O(n^2) with c = 2 and n0 = 1
Qus : Find upper bound for f(n) = n

Sol : n <= n^2 for all n >=1

so f(n) = O(n^2) with c = 1 and n0 = 1
Qus:找到f(n)=n的上界
溶胶:n=1
所以f(n)=O(n^2),其中c=1,n0=1
我很困惑,根据大O表示法,如果f(n)=n,那么f(n)=O(n),那么我想知道下面第二个例子的解决方案是否正确?

Sol : n <= 2n for all n >=1

so f(n) = O(n) with c = 2 and n0 = 1
Sol:n=1
因此f(n)=O(n),其中c=2,n0=1

这些评论的补充:

从大O的定义开始 我们可以说f(x)是O(g(x)),当且仅当存在正 数字B和非负实数B,以便:

| f(x)|小于或等于B | g(x)|对于大于B的所有数字x

因此,我们可以说对于
f(n)=nf(n)=O(n)

因为存在一个数字B(例如“2”),所以
nyes是正确的。第二个例子也没有错,f(n)也是O(n^3)。好的,如果我们考虑最紧的上界,那么哪个解是合适的?紧界θ是一个可以显示上界和下界的函数。在你的例子中,你可以证明f(n)也是ω(n),从而证明它是θ(n)。但是仅仅考虑上面所有函数的上界,我认为它们都是正确的,没有任何区别。f(n)=O(n)不是更接近紧上界吗?它更接近,但大oh的定义不关心距离。如果你对气密感兴趣,你应该使用θ。