简体   繁体   English

Big-O和Omega符号

[英]Big-O and Omega Notations

I was reading this question Big-O notation's definition . 我正在读这个问题Big-O符号的定义
But I have less than 50 reputation to comment, so I hope someone help me. 但我的评论声誉不到50,所以我希望有人帮助我。

My question is about this sentence: 我的问题是关于这句话:

There are many algorithms for which there is no single function g such that the complexity is both O(g) and Ω(g). 存在许多算法,其中没有单个函数g,使得复杂度为O(g)和Ω(g)。 For instance, insertion sort has a Big-O lower bound of O(n²) (meaning you can't find anything smaller than n²) and an Ω upper bound of Ω(n). 例如,插入排序具有O(n²)的Big-O下界(意味着您找不到小于n²的任何值)和Ω(n)的Ω上界。

for large n the O(n²) is an upper bound and Ω(n) is a lower bound, or maybe I have misunderstood? 对于大n,O(n²)是上限,Ω(n)是下限,或者我可能误解了? could someone help me? 有人能帮助我吗?

在此输入图像描述

maybe I have misunderstood? 也许我误解了?

No, you are right. 不,你是对的。

In general, the Big-O is for the upper bound and big-Ω for the lower bound. 通常,Big-O用于上限,大Ω用于下限。

For Insertion sort the worst case scenario, the upper bound is O(n 2 ). 对于插入排序最坏的情况,上限是O(n 2 )。 Ω(n) is a lower bound. Ω(n)是下限。

It seems like you find a mistake in the other answer. 看起来你在另一个答案中发现了一个错误。

has a Big-O lower bound of O(n²) 具有O(n²)的大O下界

I don't really agree with the confusing way this was phrased (since big-O is itself an upper bound), but what I'm reading here is the following: 我真的不同意这种措辞令人困惑的方式(因为big-O本身就是一个上限),但我在这里读到的是以下内容:

Big-O is an upper bound. Big-O是一个上限。

That is to say, f(n) ϵ O(g(n)) is true if |f(n)| <= k|g(n)| 也就是说,如果|f(n)| <= k|g(n)| ,则f(n) ϵ O(g(n))为真 |f(n)| <= k|g(n)| as n tends to infinity ( by definition ). 因为n倾向于无穷大( 根据定义 )。

So let's say we have a function f(n) = n 2 (which is, if we ignore constant factors, the worst-case for insertion sort). 所以我们假设我们有一个函数f(n) = n 2 (如果我们忽略常数因子,那么插入排序的最坏情况)。 We can say n 2 ϵ O(n 2 ) , but we can also say n 2 ϵ O(n 3 ) or n 2 ϵ O(n 4 ) or n 2 ϵ O(n 5 ) or .... 我们可以说n 2 ϵ O(n 2 )但是我们也可以说n 2 ϵ O(n 3 )n 2 ϵ O(n 4 )n 2 ϵ O(n 5 )或....

So the smallest g(n) we can find is n 2 . 所以我们能找到的最小g(n)n 2


But the answer you linked to is, as a whole, incorrect - insertion sort itself does not have upper or lower bounds, but rather it has best, average and worst cases, which have upper and lower bounds. 但是,您链接的答案总体而言是错误的 - 插入排序本身没有上限或下限,而是具有最佳,平均和最差情况,具有上限和下限。

See the answer I posted there. 看到我在那里发布的答案。

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

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