对Big-O表示法感到困惑

问题描述 投票:1回答:1

我是Big-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

根据Big-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
big-o asymptotic-complexity
1个回答
0
投票

这些评论的补充:

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

|f(x)|is less or equal to B|g(x)| for all numbers x that large than b

因此,可以说对于f(n)=n f(n)=O(n),因为存在数字B(例如“ 2”),所以使它成为n<=Bn。(n <= 2n,对于所有n => 0)

© www.soinside.com 2019 - 2024. All rights reserved.