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.


在本講座中铭拧,我們將繼續(xù)對(duì)漸近符號(hào)進(jìn)行正式處理劲赠。

我們已經(jīng)討論過大O符號(hào)执泰,這是迄今為止最重要和最普遍的概念,它是漸進(jìn)符號(hào)的一部分,但是為了完整起見篡撵,我想告訴您一些大O的近親斟冕,即omega和theta 。

如果big O類似于小于或等于譬胎,則ω和theta分別類似于大于或等于和等于。

但是命锄,讓我們更精確地對(duì)待它們堰乔。

Ω表示法的正式定義與大O表示法的定義非常相似。

我們說一個(gè)函數(shù)T of N是另一個(gè)函數(shù)F of N的大歐米茄脐恩,如果最終對(duì)于足夠大的N而言镐侯,它的下限是N F的常數(shù)倍。

然后,我們對(duì)常數(shù)倍的概念進(jìn)行量化苟翻,并最終以與以前完全相同的方式進(jìn)行量化韵卤,即通過顯式給出兩個(gè)常數(shù)C和N零,使得對(duì)于所有足夠大的N崇猫,N的T的下限是C乘以N的F沈条。 。

即诅炉,對(duì)于所有的N蜡歹,至少N個(gè)零。

有一張圖片就像大O符號(hào)一樣涕烧。

也許我們有一個(gè)N的函數(shù)T月而,看起來像這個(gè)綠色曲線。

然后议纯,我們有另一個(gè)函數(shù)N父款,它大于N的T。

但是瞻凤,當(dāng)我們將N的F乘以一半時(shí)铛漓,我們得到的結(jié)果最終總是低于N的T。

所以在這張照片中鲫构,這是一個(gè)例子浓恶,其中N的T確實(shí)是N的F的大歐米茄。

就常量而言结笨,我們使用的倍數(shù)C顯然只是一半包晰。

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

和以前一樣炕吸,N naught是兩個(gè)函數(shù)之間的交點(diǎn)伐憾。

因此,N零是C永遠(yuǎn)等于N永遠(yuǎn)低于N的T的時(shí)刻赫模。

那就是大歐米茄树肃。

Theta表示法等于等號(hào),因此僅表示函數(shù)既是N的F的Big O瀑罗,又是N的F的ω胸嘴。

考慮這一點(diǎn)的等效方法是,最終斩祭,將N的T夾在N F的兩個(gè)不同的常數(shù)倍之間劣像。

我將其寫下來,然后留給您確認(rèn)兩個(gè)概念是否相等摧玫。

也就是說耳奕,一個(gè)暗示另一個(gè),反之亦然。

那么屋群,N的T最終夾在N的F的兩個(gè)倍數(shù)之間是什么意思闸婴?好吧,我只是說我們選擇兩個(gè)常數(shù)芍躏。

一個(gè)小的C1和一個(gè)大的常數(shù)C2邪乍,并且對(duì)于所有N(至少N個(gè)零),T的T位于這兩個(gè)常數(shù)倍之間纸肉。

算法設(shè)計(jì)者相當(dāng)草率的一種方法是使用O表示法而不是theta表示法重罪。

因此感昼,這是一個(gè)常見的約定删掀,在本課程中憔古,我將經(jīng)常遵循該約定靴患。

讓我給你舉個(gè)例子寸爆。

假設(shè)我們有一個(gè)子例程苍凛,它對(duì)長度為N的數(shù)組進(jìn)行線性掃描龄寞。

它查看數(shù)組中的每個(gè)條目壁拉,并對(duì)每個(gè)條目進(jìn)行恒定量的工作谬俄。

因此,合并子例程或多或少將是該類型子例程的示例弃理。

因此溃论,即使這種算法(子程序)的運(yùn)行時(shí)間顯然是N的theta,它也對(duì)N個(gè)條目中的每一個(gè)都進(jìn)行恒定的工作痘昌,所以它恰好是N的theta钥勋,我們經(jīng)常會(huì)說它的運(yùn)行時(shí)間O為N.

我們不會(huì)費(fèi)心做出更強(qiáng)硬的說法,那就是N辆苔。

我們這樣做的原因是因?yàn)槟浪憔模鳛樗惴ㄔO(shè)計(jì)者,我們真正關(guān)心的是上限驻啤。

我們想要保證算法可以運(yùn)行多長時(shí)間菲驴,因此自然而然地,我們專注于上限骑冗,而不是關(guān)注下限赊瞬。

因此,請不要感到困惑贼涩。

偶爾會(huì)有一個(gè)數(shù)量顯然是N的F的theta森逮,而我只是做出一個(gè)較弱的說法,它是N的F的O磁携。

下一個(gè)測驗(yàn)旨在檢查您對(duì)這三個(gè)概念的理解:Big O褒侧,Big Omega和Big Theta表示法。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市闷供,隨后出現(xiàn)的幾起案子烟央,更是在濱河造成了極大的恐慌,老刑警劉巖歪脏,帶你破解...
    沈念sama閱讀 218,640評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件疑俭,死亡現(xiàn)場離奇詭異,居然都是意外死亡婿失,警方通過查閱死者的電腦和手機(jī)钞艇,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,254評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來豪硅,“玉大人哩照,你說我怎么就攤上這事±粮。” “怎么了飘弧?”我有些...
    開封第一講書人閱讀 165,011評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長砚著。 經(jīng)常有香客問我次伶,道長,這世上最難降的妖魔是什么稽穆? 我笑而不...
    開封第一講書人閱讀 58,755評(píng)論 1 294
  • 正文 為了忘掉前任冠王,我火速辦了婚禮,結(jié)果婚禮上舌镶,老公的妹妹穿的比我還像新娘柱彻。我一直安慰自己,他們只是感情好乎折,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,774評(píng)論 6 392
  • 文/花漫 我一把揭開白布绒疗。 她就那樣靜靜地躺著,像睡著了一般骂澄。 火紅的嫁衣襯著肌膚如雪吓蘑。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,610評(píng)論 1 305
  • 那天坟冲,我揣著相機(jī)與錄音磨镶,去河邊找鬼。 笑死健提,一個(gè)胖子當(dāng)著我的面吹牛琳猫,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播私痹,決...
    沈念sama閱讀 40,352評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼脐嫂,長吁一口氣:“原來是場噩夢啊……” “哼统刮!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起账千,我...
    開封第一講書人閱讀 39,257評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤侥蒙,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后匀奏,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體鞭衩,經(jīng)...
    沈念sama閱讀 45,717評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,894評(píng)論 3 336
  • 正文 我和宋清朗相戀三年娃善,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了论衍。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,021評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡聚磺,死狀恐怖坯台,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情咧最,我是刑警寧澤捂人,帶...
    沈念sama閱讀 35,735評(píng)論 5 346
  • 正文 年R本政府宣布御雕,位于F島的核電站矢沿,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏酸纲。R本人自食惡果不足惜捣鲸,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,354評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望闽坡。 院中可真熱鬧栽惶,春花似錦、人聲如沸疾嗅。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,936評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽代承。三九已至汁蝶,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間论悴,已是汗流浹背掖棉。 一陣腳步聲響...
    開封第一講書人閱讀 33,054評(píng)論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留膀估,地道東北人幔亥。 一個(gè)月前我還...
    沈念sama閱讀 48,224評(píng)論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像察纯,于是被迫代替她去往敵國和親帕棉。 傳聞我的和親對(duì)象是個(gè)殘疾皇子针肥,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,974評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容