Big-O和Little-O表示法之间的区别

本文翻译自:Difference between Big-O and Little-O Notation

Big-O表示法O(n)Little-O表示法o(n)之间有什么区别?


#1楼

参考:https://stackoom.com/question/5ixA/Big-O和Little-O表示法之间的区别


#2楼

f ∈ O(g) says, essentially f∈O(g)基本上说

For at least one choice of a constant k > 0, you can find a constant a such that the inequality 0 <= f(x) <= kg(x) holds for all x > a. 对于常数k > 0的至少一个选择,你可以找到一个常数a ,使得不等式0 <= f(x)<= kg(x)适用于所有x> a。

Note that O(g) is the set of all functions for which this condition holds. 注意,O(g)是该条件所适用的所有函数的集合。

f ∈ o(g) says, essentially f∈o(g)基本上说

For every choice of a constant k > 0, you can find a constant a such that the inequality 0 <= f(x) < kg(x) holds for all x > a. 对于常数k > 0的每个选择,你可以找到一个常数a ,使得不等式0 <= f(x)<kg(x)适用于所有x> a。

Once again, note that o(g) is a set. 再次注意o(g)是一组。

In Big-O, it is only necessary that you find a particular multiplier k for which the inequality holds beyond some minimum x . 在Big-O中,只需要找到一个特定的乘数k ,其中不等式保持超过某个最小x

In Little-o, it must be that there is a minimum x after which the inequality holds no matter how small you make k , as long as it is not negative or zero. 在Little-o中,必须存在一个最小x,在此之后,不管你做出多小的k ,不等式都会成立,只要它不是负数或零。

These both describe upper bounds, although somewhat counter-intuitively, Little-o is the stronger statement. 这两个都描述了上限,虽然有点违反直觉,Little-o是更强的说法。 There is a much larger gap between the growth rates of f and g if f ∈ o(g) than if f ∈ O(g). 如果f∈o(g),则f和g的增长率之间存在比f∈O(g)更大的差距。

One illustration of the disparity is this: f ∈ O(f) is true, but f ∈ o(f) is false. 差异的一个例子是:f∈O(f)为真,但f∈o(f)为假。 Therefore, Big-O can be read as "f ∈ O(g) means that f's asymptotic growth is no faster than g's", whereas "f ∈ o(g) means that f's asymptotic growth is strictly slower than g's". 因此,Big-O可以被解读为“f∈O(g)意味着f的渐近增长不比g更快”,而“f∈o(g)意味着f的渐近增长严格地慢于g”。 It's like <= versus < . 这就像<=<

More specifically, if the value of g(x) is a constant multiple of the value of f(x), then f ∈ O(g) is true. 更具体地,如果g(x)的值是f(x)的值的常数倍,则f∈O(g)为真。 This is why you can drop constants when working with big-O notation. 这就是为什么在使用big-O表示法时可以删除常量的原因。

However, for f ∈ o(g) to be true, then g must include a higher power of x in its formula, and so the relative separation between f(x) and g(x) must actually get larger as x gets larger. 然而,对于f∈o(g)为真,则g必须在其公式中包括更高的x次 ,因此当x变大时,f(x)和g(x)之间的相对间隔实际上必须变大。

To use purely math examples (rather than referring to algorithms): 要使用纯数学示例(而不是参考算法):

The following are true for Big-O, but would not be true if you used little-o: 对于Big-O,以下情况属实,但如果使用little-o则不然:

  • x² ∈ O(x²) x²∈O(x²)
  • x² ∈ O(x² + x) x²∈O(x²+ x)
  • x² ∈ O(200 * x²) x²∈O(200 *x²)

The following are true for little-o: 对于little-o,以下情况属实:

  • x² ∈ o(x³) x²∈o(x³)
  • x² ∈ o(x!) x²∈o(x!)
  • ln(x) ∈ o(x) ln(x)∈o(x)

Note that if f ∈ o(g), this implies f ∈ O(g). 注意,如果f∈o(g),这意味着f∈O(g)。 eg x² ∈ o(x³) so it is also true that x² ∈ O(x³), (again, think of O as <= and o as < ) 例如x²∈o(x³)所以x²∈O(x³)也是如此,(再次将O视为<=而o视为<


#3楼

Big-O is to little-o as is to < . O是 o,因为< Big-O is an inclusive upper bound, while little-o is a strict upper bound. Big-O是包含上限,而little-o是严格的上限。

For example, the function f(n) = 3n is: 例如,函数f(n) = 3n是:

  • in O(n²) , o(n²) , and O(n) in O(n²)o(n²)O(n)
  • not in O(lg n) , o(lg n) , or o(n) 不在O(lg n)o(lg n)o(n)

Analogously, the number 1 is: 类似地,数字1是:

  • ≤ 2 , < 2 , and ≤ 1 ≤ 2< 2≤ 1
  • not ≤ 0 , < 0 , or < 1 ≤ 0< 0< 1

Here's a table, showing the general idea: 这是一张表,显示了一般的想法:

大o桌

(Note: the table is a good guide but its limit definition should be in terms of the superior limit instead of the normal limit. For example, 3 + (n mod 2) oscillates between 3 and 4 forever. It's in O(1) despite not having a normal limit, because it still has a lim sup : 4.) (注意:该表是一个很好的指南,但它的限制定义应该是上限而不是正常限制。例如, 3 + (n mod 2)永远在3和4之间振荡。它在O(1)尽管没有一个正常范围,因为它仍然有一个lim sup :4)

I recommend memorizing how the Big-O notation converts to asymptotic comparisons. 我建议记住Big-O符号如何转换为渐近比较。 The comparisons are easier to remember, but less flexible because you can't say things like n O(1) = P. 比较更容易记住,但灵活性较差,因为你不能说n O(1) = P.


#4楼

I find that when I can't conceptually grasp something, thinking about why one would use X is helpful to understand X. (Not to say you haven't tried that, I'm just setting the stage.) 我发现当我无法在概念上掌握某些东西时,思考为什么要使用X有助于理解X.(不是说你没有尝试过,我只是在设置舞台。)

[stuff you know]A common way to classify algorithms is by runtime, and by citing the big-Oh complexity of an algorithm, you can get a pretty good estimation of which one is "better" -- whichever has the "smallest" function in the O! [你知道的东西]分类算法的常用方法是运行时,通过引用算法的大复杂性,你可以很好地估计哪一个是“更好” - 无论哪个具有“最小”功能在O! Even in the real world, O(N) is "better" than O(N²), barring silly things like super-massive constants and the like.[/stuff you know] 即使在现实世界中,O(N)比O(N²)“更好”,除非像超大质量常数之类的傻事。[/你知道的东西]

Let's say there's some algorithm that runs in O(N). 假设有一些在O(N)中运行的算法。 Pretty good, huh? 很好,对吧? But let's say you (you brilliant person, you) come up with an algorithm that runs in O( NloglogloglogN ). 但是,让我们说你(你很聪明的人,你)想出一个在O( N / loglogloglogN )中运行的算法。 YAY! 好极了! Its faster! 它更快! But you'd feel silly writing that over and over again when you're writing your thesis. 但是当你撰写论文时,你会一遍又一遍地写下傻傻的写作。 So you write it once, and you can say "In this paper, I have proven that algorithm X, previously computable in time O(N), is in fact computable in o(n)." 所以你写了一次,然后你可以说“在本文中,我已经证明了算法X,以前可以在时间O(N)中计算,实际上是在o(n)中可计算的。”

Thus, everyone knows that your algorithm is faster --- by how much is unclear, but they know its faster. 因此,每个人都知道你的算法更快 - 有多少不清楚,但他们知道它更快。 Theoretically. 理论上。 :) :)

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值