简体   繁体   English

不同渐近符号之间有什么区别?

[英]What is difference between different asymptotic notations?

I am really very confused in asymptotic notations.我对渐近符号真的很困惑。 As far as I know, Big-O notation is for worst cast, omega is for best case and theta is for average case.据我所知,Big-O 表示法是最差的,omega 是最好的情况,theta 是平均情况。 However, I have always seen Big O being used everywhere, even for best case.然而,我总是看到 Big O 无处不在,即使在最好的情况下也是如此。 For eg in the following link, see the table where time complexities of different sorting algorithms are mentioned-例如,在以下链接中,请参阅提及不同排序算法的时间复杂度的表格 -

https://en.wikipedia.org/wiki/Best,_worst_and_average_case https://en.wikipedia.org/wiki/Best,_worst_and_average_case

Everywhere in the table, big O notation is used irrespective of whether it is best case, worst case or average case.表中的每个地方都使用大 O 表示法,无论是最好的情况、最坏的情况还是平均情况。 Then what is the use of other two notations and where do we use it?那么另外两种记法有什么用呢,又用在什么地方呢?

Big O is for upper bound, not for worst case! Big O 用于上限,而不是最坏的情况! There is no notation specifically for worst case/best case.没有专门针对最坏情况/最好情况的符号。 The examples you are talking about all have Big O because they are all upper bounded by the given value.您正在谈论的示例都有大 O,因为它们都以给定值为上限。 I suggest you take another look at the book from which you learned the basics because this is immensely important to understand :)我建议你再看看你从中学习基础知识的书,因为这对理解非常重要:)

EDIT: Answering your doubt- because usually, we are bothered with our at-most performance ie when we say, our algorithm performs in O(logn) in the best case-scenario, we know that its performance will not be worse than logarithmic time in the given scenario.编辑:回答您的疑问 - 因为通常,我们对我们的最高性能感到困扰,即当我们说我们的算法在最佳情况下以 O(logn) 执行时,我们知道它的性能不会比对数时间差在给定的场景中。 It is the upper bound that we seek to reduce usually and hence we usually mention big O to compare algorithms.这是我们通常寻求减少的上限,因此我们通常会提到大 O 来比较算法。 (not to say that we never mention the other two) (并不是说我们从未提及其他两个)

As far as I know, Big-O notation is for worst cast, omega is for best case and theta is for average case.据我所知,Big-O 表示法是最差的,omega 是最好的情况,theta 是平均情况。

They aren't .他们不是 Omicron is for (asymptotic) upper bound, omega is for lower bound and theta is for tight bound, which is both an upper and a lower bound. Omicron 是(渐近)上限,omega 是下界,theta 是界,既是上限又是下界。 If the lower and upper bound of an algorithm are different, then the complexity cannot be expressed with theta notation.如果算法的下界和上限不同,则复杂度无法用 theta 符号表示。

The concept of upper,lower,tight bound are orthogonal to the concept of best,average,worst case.上限、下限、紧边界的概念与最佳、平均、最坏情况的概念正交。 You can analyze the upper bound of each case, and you can analyze different bounds of the worst case (and also any other combination of the above).您可以分析每种情况的上限,也可以分析最坏情况的不同界限(以及上述任何其他组合)。

Asymptotic bounds are always in relation to the set of variables in the expression.渐近边界总是与表达式中的变量集有关。 For example, O(n) is in relation to n .例如, O(n)n The best, average and worst cases emerge from everything else but n .最好的、平均的和最坏的情况来自除n所有其他情况。 For example, if n is the number of elements, then the different cases might emerge from the order of the elements, or the number of unique elements, or the distribution of values.例如,如果n是元素的数量,那么不同的情况可能来自元素的顺序、唯一元素的数量或值的分布。

However, I have always seen Big O being used everywhere, even for best case.然而,我总是看到 Big O 无处不在,即使在最好的情况下也是如此。

That's because the upper bound is almost always the one that is the most important and interesting when describing an algorithm .这是因为在描述算法时,上限几乎总是最重要和最有趣的上限。 We rarely care about the lower bound.我们很少关心下限。 Just like we rarely care about the best case.就像我们很少关心最好的情况一样。

The lower bound is sometimes useful in describing a problem that has been proven to have a particular complexity.下限有时可用于描述已被证明具有特定复杂性的问题。 For example, it is proven that worst case complexity of all general comparison sorting algorithms is Ω(n log n) .例如,已证明所有通用比较排序算法的最坏情况复杂度为Ω(n log n) If the sorting algorithm is also O(n log n) , then by definition, it is also Θ(n log n) .如果排序算法也是O(n log n) ,那么根据定义,它也是Θ(n log n)

O(...) basically means "not (much) slower than ...". O(...)基本上意味着“不(远)比...慢”。
It can be used for all three cases ("the worst case is not slower than", "the best case is not slower than", and so on).它可以用于所有三种情况(“最坏情况不慢于”,“最好情况不慢于”,等等)。

Omega is the oppsite: You can say, something can't be much faster than ... . Omega 正好相反:您可以说,某些事情不可能比 ...快得多 Again, it can be used with all three cases.同样,它可以用于所有三种情况。 Compared to O(...) , it's not that important, because telling someone "I'm certain my program is not faster than yours" is nothing to be proud of.O(...)相比,这并不重要,因为告诉某人“我确定我的程序没有你的快”并没有什么值得骄傲的。

Theta is a combination: It's "(more or less) as fast as" ..., not just slower/faster. Theta 是一个组合:它“(或多或少)与……一样快”,而不仅仅是更慢/更快。

The Big-O notation is somethin like this >= in terms of asymptotic equality. Big-O表示法类似于这样>=在渐近相等方面。

For example if you see this :例如,如果你看到这个:

x = O(x^2) it does say x <= x^2 (in asymptotic terms). x = O(x^2)它确实说x <= x^2 (在渐近术语中)。

And it does mean "x is at most as complex as x^2", which is something that you are usually interesting it.它确实意味着“x 至多与 x^2 一样复杂”,这是您通常感兴趣的东西。

Even when you compare Best/Average case, you can say "At best possible input, I will have AT MOST this complexity".即使在比较最佳/平均情况时,您也可以说“在最好的输入中,我最多会有这种复杂性”。

There are two things mixed up: Big O, Omega, Theta, are purely mathematical constructions.有两件事混为一谈:Big O、Omega、Theta 是纯粹的数学结构。 For example, O (f (N)) is the set of functions which are less than c * f (n), for some c > 0, and for all n >= some minimum value N0.例如,O (f (N)) 是小于 c * f (n) 的函数集,对于某些 c > 0,并且对于所有 n >= 某个最小值 N0。 With that definition, n = O (f (n^4)), because n ≤ n^4.根据该定义,n = O (f (n^4)),因为 n ≤ n^4。 100 = O (f (n)), because 100 <= n for n ≥ 100, or 100 <= 100 * n for n ≥ 1. 100 = O (f (n)),因为 n ≥ 100 时 100 <= n,或者 n ≥ 1 时 100 <= 100 * n。

For an algorithm, you want to give worst case speed, average case speed, rarely the best case speed, sometimes amortised average speed (that's when running an algorithm once does work that can be used when it's run again. Like calculating n! for n = 1, 2, 3, ... where each calculation can take advantage of the previous one).对于算法,您希望给出最坏情况下的速度,平均情况下的速度,很少是最佳情况下的速度,有时是摊销平均速度(即运行一次算法确实有效,再次运行时可以使用。就像计算 n! for n = 1, 2, 3, ... 其中每个计算都可以利用前一个)。 And whatever speed you measure, you can give a result in one of the notations.无论你测量什么速度,你都可以用一种符号给出结果。

For example, you might have an algorithm where you can prove that the worst case is O (n^2), but you cannot prove whether there are faster special cases or not, and you also cannot prove that the algorithm isn't actually faster, like O (n^1.9).例如,您可能有一个算法,您可以证明最坏的情况是 O(n^2),但您无法证明是否存在更快的特殊情况,也无法证明该算法实际上并没有更快,就像 O (n^1.9)。 So O (n^2) is the only thing that you can prove.所以 O (n^2) 是唯一可以证明的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM