5.2 「THE MASTER METHOD」Motivation - Part1

In this series of videos, we'll study the master method, which is a general

mathematical tool for analyzing the running time of divide-and-conquer

algorithms. We'll begin, in this video, motivating the method, then we'll give its

formal description. That'll be followed by a video working through six examples.

Finally, we'll conclude with three videos that discuss proof of the master method,

with a particular emphasis on the conceptual interpretation of the master

method's three cases. So, lemme say at the outset that this lecture's a little bit

more mathematical than the previous two, but it's certainly not just math for

math's sake. We'll be rewarded for our work with this powerful tool, the master

method, which has a lot of. The power it will give us good advice on which divide

and conquer algorithms are likely to run quickly and which ones are likely to run

less quickly, indeed it's sort of a general truism that. Novel algorithmic

ideas often require mathematical analyis to properly evaluate. This lecture will be

one example of that truism. As a motivating example, consider the

computational problem of multiplying two n-digit numbers. Recall from our first set

of lectures that we all learned the iterative grade school multiplication

algorithm, and that, that requires a number of basic operations, additions and

multiplications between single digits, which grows quadratically with the number

of digits n. On the other hand, we also discussed an interesting recursive

approach using the divide and conquer paradigm. So recall divide and conquer

necessitates identifying smaller subproblems. So for integer

multiplication, we need to identify smaller numbers that we wanna multiply. So

we proceeded in the obvious way, breaking each of the two numbers into its left half

of the digits, and its right half of the digits. For convenience, I'm assuming that

the number of digits N is even, but it really doesn't matter. Having decomposed X

and Y in this way, we can now expand the product and see what we get. So let's put

a box around this expression, and call it star. So we began with the sort of obvious

recursive algorithm, where we just evaluate the expression star in the

straightforward way. That is, star contains four products involving N over

two digit numbers. A, C, A, D, V, C, and B, D. So we make four recursive calls to

compute them, and then we complete the evaluation in the natural way. Namely, we

append zeros as necessary, and add up these three terms to get the final result.

The way wereason about the running time of recursive algorithms like this one is

using what's called a recurrence. So to intrduce a recurrence let me first make

some notation. T of N. This is going to be the quantity that we really care about,

the quantity that we want to upward boun. Namely this will be the worse case number

of operations that this recursive algorithm requires to multiply two end

digit numbers. A recurrence, then, is simply a way to express T of N in terms of

T of smaller numbers. That is, the running time of an algorithm in terms of the work

done by its recursive calls. So every recurrence has two ingredients. First of

all, it has a base case describing the running time when there's no further

recursion. And in this integer multiplication algorithm, like in most

divide and conquer algorithms, the base case is easy. Once you get down to a small

input, in this case, two one digit numbers, then the running time in just

constant. All you do is multiply the two digits and return the result. So I'm gonna

express that by just declaring the T of one, the time needed to multiply one digit

numbers, is bounded above by a constant. I'm not gonna bother to specify what this

constant is. You can think of it as one or two if you like. It's not gonna matter for

what's to follow. The second ingredient in a recurrence is the important one and it's

what happens in the general case, when you're not in the base case and you make

recursive calls. And all you do is write down the running time in terms of two

pieces. First of all, the work done by the recursive calls and second of all, the

work that's done right here, now. Work done outside of the recursive calls. So on

the left hand side of this general case we just write T of N and then we want

upper bound on T of N in terms of the work done in recursive goals and the work done

outside of recursive goals. And I hope it's self evident what the recurrence

should be in this recursive algorithm for integer multiplication, as we discussed

there's exactly four recursive calls and each is invoked on a pair of N over two

digit numbers so that gives four times the time needed to multiply ten over two digit

numbers. So what do we do outside of the recursive call well we've had the

recursive calls with a bunch of zero's and we add them up. And I'll leave it to you

to verify that grade school addition, in fact runs in time linear in the number of

digits. So putting it all together the amount of work we do outside of the

recursive calls is linear. That is it's big O. Of N. Let's move on to the second,

more clever, recursive algorithm for integer multiplication which dates back to

Gas. Gauss's insight was to realize that, in the expression, star, that we're trying

to evaluate, there's really only three fundamental quantities that we care about,

the coefficients for each of the three terms in the expression. So, this leads us

to hope that, perhaps, we can compute these three quantities using only three

recursive calls, rather than four. And, indeed, we can. So what we do is we

recursively compute A times C, like before, and B times D like before. But

then we compute the product of A plus B with C plus D. And the very cute fact. Is

if we number these three products one two and three that's the final quantity that

we care about the coefficients of the ten to the N over two term namely AD plus BC.

Is nothing more than the third product minus each of the first two. So that's the

new algorithm, what's the new occurrence? The base case obviously is exactly the

same as before. So the question then is, how does the general case change, and,

I'll let you answer this in the following quiz.



Motivation - Question 1

Which recurrence best describes the running time of the Gauss' algorithm for integer multiplication?

??(??)≤2??(??/2)+??(??^2)

??(??)≤3??(??/2)+??(??)

??(??)≤4??(??/2)+??(??)

??(??)≤4??(??/2)+??(??^2)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子最易,更是在濱河造成了極大的恐慌嚷堡,老刑警劉巖债热,帶你破解...
    沈念sama閱讀 218,607評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件届榄,死亡現(xiàn)場(chǎng)離奇詭異匀哄,居然都是意外死亡聊训,警方通過查閱死者的電腦和手機(jī)抱究,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,239評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來带斑,“玉大人鼓寺,你說我怎么就攤上這事勋拟。” “怎么了妈候?”我有些...
    開封第一講書人閱讀 164,960評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵敢靡,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我苦银,道長(zhǎng)啸胧,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,750評(píng)論 1 294
  • 正文 為了忘掉前任幔虏,我火速辦了婚禮纺念,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘想括。我一直安慰自己陷谱,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,764評(píng)論 6 392
  • 文/花漫 我一把揭開白布主胧。 她就那樣靜靜地躺著叭首,像睡著了一般习勤。 火紅的嫁衣襯著肌膚如雪踪栋。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,604評(píng)論 1 305
  • 那天图毕,我揣著相機(jī)與錄音夷都,去河邊找鬼。 笑死予颤,一個(gè)胖子當(dāng)著我的面吹牛囤官,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蛤虐,決...
    沈念sama閱讀 40,347評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼党饮,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了驳庭?” 一聲冷哼從身側(cè)響起刑顺,我...
    開封第一講書人閱讀 39,253評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎饲常,沒想到半個(gè)月后蹲堂,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,702評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡贝淤,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,893評(píng)論 3 336
  • 正文 我和宋清朗相戀三年柒竞,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片播聪。...
    茶點(diǎn)故事閱讀 40,015評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡朽基,死狀恐怖布隔,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情稼虎,我是刑警寧澤执泰,帶...
    沈念sama閱讀 35,734評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站渡蜻,受9級(jí)特大地震影響术吝,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜茸苇,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,352評(píng)論 3 330
  • 文/蒙蒙 一排苍、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧学密,春花似錦淘衙、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,934評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至哭靖,卻和暖如春具垫,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背试幽。 一陣腳步聲響...
    開封第一講書人閱讀 33,052評(píng)論 1 270
  • 我被黑心中介騙來泰國(guó)打工筝蚕, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人铺坞。 一個(gè)月前我還...
    沈念sama閱讀 48,216評(píng)論 3 371
  • 正文 我出身青樓起宽,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親济榨。 傳聞我的和親對(duì)象是個(gè)殘疾皇子坯沪,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,969評(píng)論 2 355