Big-O and Omega Notations

若如初见. 提交于 2020-01-02 07:08:20

问题


I was reading this question Big-O notation's definition.
But I have less than 50 reputation to comment, so I hope someone help me.

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). 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).

for large n the O(n²) is an upper bound and Ω(n) is a lower bound, or maybe I have misunderstood? could someone help me?


回答1:


has a Big-O lower bound of O(n²)

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 is an upper bound.

That is to say, f(n) ϵ O(g(n)) is true if |f(n)| <= k|g(n)| as n tends to infinity (by definition).

So let's say we have a function f(n) = n2 (which is, if we ignore constant factors, the worst-case for insertion sort). We can say n2 ϵ O(n2), but we can also say n2 ϵ O(n3) or n2 ϵ O(n4) or n2 ϵ O(n5) or ....

So the smallest g(n) we can find is n2.


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.




回答2:


maybe I have misunderstood?

No, you are right.

In general, the Big-O is for the upper bound and big-Ω for the lower bound.

For Insertion sort the worst case scenario, the upper bound is O(n2). Ω(n) is a lower bound.

It seems like you find a mistake in the other answer.



来源:https://stackoverflow.com/questions/46129461/big-o-and-omega-notations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!