2.4「Stanford Algorithms」ASYMPTOTIC ANALYSIS|Big Omega and Theta - Part 1

In this lecture, we'll continue our formal treatment of asymptotic notation.

We've already discussed big O notation, which is by far the most important and ubiquitous concept that's part of asymptotic notation, but, for completeness, I do want to tell you about a couple of close relatives of big O, namely omega and theta.

If big O is analogous to less than or equal to, then omega and theta are analogous to greater than or equal to, and equal to, respectively.

But let's treat them a little more precisely.

The formal definition of omega notation closely mirrors that of big O notation.

We say that one function, T of N, is big omega of another function, F of N, if eventually, that is for sufficiently large N, it's lower bounded by a constant multiple of F of N.

And we quantify the ideas of a constant multiple and eventually in exactly the same way as before, namely via explicitly giving two constants, C and N naught, such that T of N is bounded below by C times F of N for all sufficiently large N.

That is, for all N at least N naught.

There's a picture just like there was for big O notation.

Perhaps we have a function T of N which looks something like this green curve.

And then we have another function F of N which is above T of N.

But then when we multiply F of N by one half, we get something that, eventually, is always below T of N.

So in this picture, this is an example where T of N is indeed big Omega of F of N.

As far as what the constants are, well, the multiple that we use, C, is obviously just one half.

That's what we're multiplying F of N by.

And as before, N naught is the crossing point between the two functions.

So, N naught is the point after which C times F of N always lies below T of N forevermore.

So that's Big Omega.

Theta notation is the equivalent of equals, and so it just means that the function is both Big O of F of N and Omega of F of N.

An equivalent way to think about this is that, eventually, T of N is sandwiched between two different constant multiples of F of N.

I'll write that down, and I'll leave it to you to verify that the two notions are equivalent.

That is, one implies the other and vice versa.

So what do I mean by T of N is eventually sandwiched between two multiples of F of N? Well, I just mean we choose two constants.

A small one, C1, and a big constant, C2, and for all N at least N naught, T of N lies between those two constant multiples.

One way that algorithm designers can be quite sloppy is by using O notation instead of theta notation.

So that's a common convention and I will follow that convention often in this class.

Let me give you an example.

Suppose we have a subroutine, which does a linear scan through an array of length N.

It looks at each entry in the array and does a constant amount of work with each entry.

So the merge subroutine would be more or less an example of a subroutine of that type.

So even though the running time of such an algorithm, a subroutine, is patently theta of N, it does constant work for each of N entries, so it's exactly theta of N, we'll often just say that it has running time O of N.

We won't bother to make the stronger statement that it's theta of N.

The reason we do that is because you know, as algorithm designers, what we really care about is upper bounds.

We want guarantees on how long our algorithms are going to run, so naturally we focus on the upper bounds and not so much on the lower bound side.

So don't get confused.

Once in a while, there will a quantity which is obviously theta of F of N, and I'll just make the weaker statement that it's O of F of N.

The next quiz is meant to check your understanding of these three concepts: Big O, Big Omega, and Big Theta notation.


在本讲座中,我们将继续对渐近符号进行正式处理。

我们已经讨论过大O符号,这是迄今为止最重要和最普遍的概念,它是渐进符号的一部分,但是为了完整起见,我想告诉您一些大O的近亲,即omega和theta 。

如果big O类似于小于或等于,则ω和theta分别类似于大于或等于和等于。

但是,让我们更精确地对待它们。

Ω表示法的正式定义与大O表示法的定义非常相似。

我们说一个函数T of N是另一个函数F of N的大欧米茄,如果最终对于足够大的N而言,它的下限是N F的常数倍。

然后,我们对常数倍的概念进行量化,并最终以与以前完全相同的方式进行量化,即通过显式给出两个常数C和N零,使得对于所有足够大的N,N的T的下限是C乘以N的F。 。

即,对于所有的N,至少N个零。

有一张图片就像大O符号一样。

也许我们有一个N的函数T,看起来像这个绿色曲线。

然后,我们有另一个函数N,它大于N的T。

但是,当我们将N的F乘以一半时,我们得到的结果最终总是低于N的T。

所以在这张照片中,这是一个例子,其中N的T确实是N的F的大欧米茄。

就常量而言,我们使用的倍数C显然只是一半。

那就是我们要乘以N的F。

和以前一样,N naught是两个函数之间的交点。

因此,N零是C永远等于N永远低于N的T的时刻。

那就是大欧米茄。

Theta表示法等于等号,因此仅表示函数既是N的F的Big O,又是N的F的ω。

考虑这一点的等效方法是,最终,将N的T夹在N F的两个不同的常数倍之间。

我将其写下来,然后留给您确认两个概念是否相等。

也就是说,一个暗示另一个,反之亦然。

那么,N的T最终夹在N的F的两个倍数之间是什么意思?好吧,我只是说我们选择两个常数。

一个小的C1和一个大的常数C2,并且对于所有N(至少N个零),T的T位于这两个常数倍之间。

算法设计者相当草率的一种方法是使用O表示法而不是theta表示法。

因此,这是一个常见的约定,在本课程中,我将经常遵循该约定。

让我给你举个例子。

假设我们有一个子例程,它对长度为N的数组进行线性扫描。

它查看数组中的每个条目,并对每个条目进行恒定量的工作。

因此,合并子例程或多或少将是该类型子例程的示例。

因此,即使这种算法(子程序)的运行时间显然是N的theta,它也对N个条目中的每一个都进行恒定的工作,所以它恰好是N的theta,我们经常会说它的运行时间O为N.

我们不会费心做出更强硬的说法,那就是N。

我们这样做的原因是因为您知道,作为算法设计者,我们真正关心的是上限。

我们想要保证算法可以运行多长时间,因此自然而然地,我们专注于上限,而不是关注下限。

因此,请不要感到困惑。

偶尔会有一个数量显然是N的F的theta,而我只是做出一个较弱的说法,它是N的F的O。

下一个测验旨在检查您对这三个概念的理解:Big O,Big Omega和Big Theta表示法。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,172评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,346评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,788评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,299评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,409评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,467评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,476评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,262评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,699评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,994评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,167评论 1 343
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,827评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,499评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,149评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,387评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,028评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,055评论 2 352

推荐阅读更多精彩内容