Transcript3.docx
- 文档编号:7406972
- 上传时间:2023-05-11
- 格式:DOCX
- 页数:12
- 大小:29.25KB
Transcript3.docx
《Transcript3.docx》由会员分享,可在线阅读,更多相关《Transcript3.docx(12页珍藏版)》请在冰点文库上搜索。
Transcript3
VideoLectures-Lecture3
Topicscovered:
Divide-and-Conquer:
Strassen,Fibonacci,PolynomialMultiplication
Transcript-Lecture3
Goodmorningeveryone.Todaywearegoingtodosomealgorithms,backtoalgorithms,andwearegoingtousealotofthe,well,someofthesimplermathematicsthatwedevelopedlastclasslikethemastertheoremforsolvingrecurrences.Wearegoingtousethisalot.Becausewearegoingtotalkaboutrecursivealgorithmstoday.Andsowewillfindtheirrunningtimeusingthemastertheorem.Thisisjustthesameasitwaslasttime,Ihope,unlessImadeamistake.Acoupleofreminders.YoushouldallgotorecitationonFriday.Thatisrequired.Ifyouwantto,youcangotohomeworklabonSunday.Thatmaybeagoodexcuseforyoutoactuallyworkonyourproblemsetafewhoursearly.
Well,actually,it'sdueonWednesdaysoyouhavelotsoftime.AndthereisnoclassonMonday.ItistheholidayknownasStudentHoliday,sodon'tcome.TodaywearegoingtocoversomethingcalledDivideandConquer.AlsoknownasdivideandruleordivideetimperaforthoseofyouwhoknowLatin,whichisatriedandtestedwayofconqueringalandbydividingitintosectionsofsomekind.Itcouldbedifferentpoliticalfactions,differentwhatever.Andthensomehowmakingthemnolongerlikeeachother.Likestartingafamilyfeudisalwaysagoodmethod.Youshouldrememberthisonyourquiz.I'mkidding.
Andifyoucanseparatethisbigpowerstructureintolittlepowerstructuressuchthatyoudominateeachlittlepowerstructurethenyoucanconquerallofthemindividually,aslongasyoumakesuretheydon'tgetbacktogether.Thatisdivideandconqueraspracticed,say,bytheBritish.ButtodaywearegoingtododivideandconqueraspracticedinCormen,Leiserson,RivestandSteinoreveryotheralgorithmtextbook.Thisisaverybasicandverypowerfulalgorithmdesigntechnique.So,thisisourfirstrealalgorithmdesignexperience.
Wearestillsortofmostlyintheanalysismode,butwearegoingtodosomeactualdesign.We'regoingtocovermaybeonlythreeorfourmajordesigntechniques.Thisisoneofthem,soitisreallyimportant.Anditwillleadtoallsortsofrecurrences,sowewillgettouseeverythingfromlastclassandseewhyitisuseful.Asyoumightexpect,thefirststepindivide-and-conquerisdivideandthesecondstepisconquer.
Butyoumaynothaveguessedthattherearethreesteps.AndIamleavingsomeblankspacehere,soyoushould,too.Divide-and-conquerisanalgorithmictechnique.Youaregivensomebigproblemyouwanttosolve,youdon'treallyknowhowtosolveitinanefficientway,soyouaregoingtosplititupintosubproblems.Thatisthedivide.Youaregoingtodividethatproblem,ormorepreciselytheinstanceofthatproblem,theparticularinstanceofthatproblemyouhaveintosubproblems.Andthosesubproblemsshouldbesmallerinsomesense.AndsmallermeansnormallythatthevalueofNissmallerthanitwasintheoriginalproblem.So,yousortofmadesomeprogress.Nowyouhaveone,ormorelikelyyouhaveseveralsubproblemsyouneedtosolve.Eachofthemissmaller.So,yourecursivelysolveeachsubproblem.
Thatistheconquerstep.Youconquereachsubproblemrecursively.Andthensomehowyoucombinethosesolutionsintoasolutionforthewholeproblem.So,thisisthegeneraldivide-and-conquerparadigm.Andlotsofalgorithmsfitit.Youhavealreadyseenonealgorithmthatfitsthisparadigm,ifyoucanremember.Mergesort,good.Wow,youareallawake.I'mimpressed.So,wesawmergesort.And,ifIamclever,Icouldfititinthisspace.Sure.Let'sbeclever.Aquickreviewonmergesort.Phrasedinthis1,2,3kindofmethod.Thefirststepwastodivideyourarrayintotwohalves.Thisreallydoesn'tmeananythingbecauseyoujustsortofthink,oh,Iwillpretendmyarrayisdividedintotwohalves.
Thereisnoworkhere.Thisiszerotime.Youjustlookatyourarray.Hereisyourarray.Iguessmaybeyoucomputen/2andtakethefloor.Thattakesconstanttime.AndyousayOK,Iampretendingmyarrayisnowdividedintotheleftpartandtherightpart.Andthentheinterestingpartisthatyourecursivelysolveeachone.That'stheconquer.Werecursivelysorteachsubarray.Andthenthethirdstepistocombinethosesolutions.Andsoherewereallyseewhatthismeans.Wenowhaveasortedversionofthisarraybyinduction.Wehaveasortedversionofthisarraybyinduction.
Wenowwantthesortedversionofthewholearray.Andwesawthatwasthemergeproblem,mergingtwosortedarrays.Andthatwesawhowtodoinlineartime,orderntime.Iamnotgoingtorepeatthat,butthepointisitfallsintothatframework.Iwanttowritetherunningtimeandmergesortasarecurrence.Youhavealreadyseentherecurrence,youhavealreadybeentoldthesolution,butnowweactuallyknowhowtosolveit.And,furthermore,everyalgorithmthatfollowsthedivide-and-conquerparadigmwillhavearecurrenceofprettymuchthesameform,verymuchlikeourgoodfriendthemastermethod.Let'sdoitformergesortwherewesortofalreadyknowtheanswerandgetabitofpractice.
Thisisthemergesortrecurrence.Youshouldknowandlovethisrecurrencebecauseitcomesupallovertheplace.Itcomesfromthisgeneralapproachbyjustseeingwhatarethesizesofthesubproblemsyouaresolvingandhowmanythereareandhowmuchextraworkyouaredoing.Youhaveherethesizeofthesubproblems.Ithappensherethatbothsubproblemshavethesamesizeroughly.Thereisthissloppinessthatwehave,whichreallyshouldbeToffloorofnover2plusTofceilingofnover2.
AndwhenyougotorecitationonFridayyouwillseewhythatisOK,thefloorsandceilingsdon'tmatter.Thereisatheoremyoucanprovethatthat'shappy.YoucanassumethatNisapowerof2,butwearejustgoingtoassumethatfornow.Wejusthavetwoproblemswithsizenover2.This2isthenumberofsubproblems.Andthisordernisalltheextraworkwearedoing.Now,whatistheextraworkpotentially?
Well,theconqueringisalwaysjustrecursion.Thereissortofnoworkthereexceptthisleadpart.Thedividinginthiscaseistrivial,butingeneralitmightinvolvesomework.Andthecombininghereinvolveslinearwork.So,thisisthedivide-and-conquerrunningtimes.
So,thisisthenonrecursivework.Andthatisgenerallyhowyouconvertadivide-and-conqueralgorithmintoarecurrence.It'sreallyeasyandyouusuallygettoapplythemastermethod.HereweareinCase2.Verygood.ThisisCase2.Andkiszerohere.Andsointherecursiontree,allofthecostsareroughlythesame.Theyareallntothelogbasebofa.Herentothelogbase2of2isjustn.Sotheseareequal.Wegetanextralogfactorbecauseofthenumberoflevelsintherecursiontree.Remembertheintuitionbehindthemastermethod.Thisisnlogn,andthatisgood.Mergesortisafastsortingalgorithmnlogn.Insertionsortwasnsquared.Insomesense,nlognisthebestyoucando.Wewillcoverthatintwolecturesfromnow,butjustforeshadowing.
Todaywearegoingtododifferentdivide-and-conqueralgorithms.Sortingisoneproblem.Thereareallsortsofproblemswemightwanttosolve.Itturnsoutalotofthemyoucanapplydivide-and-conquerto.Noteveryproblem.Likehowtowakeupinthemorning,it'snotsoeasytosolveadivide-and-conquer,althoughmaybethat'sagoodproblemsetproblem.Thenextdivide-and-conqueralgorithmwearegoingtolookatisevensimplerthansorting,evensimplerthanmergesort,butitdriveshomethepointofwhenyouhaveonlyonesubproblem.Howmanypeoplehaveseenbinarysearchbefore?
Anyonehasn't?
One,OK.Iwillgoveryquicklythen.YouhavesomeelementX.YouwanttofindXinasortedarray.
Howmanypeoplehadnotseenitbeforetheysawitinrecitation?
Noone,OK.Good.Youhaveseenitinanotherclass,probably6.001orsomething.Verygood.Youtooktheprerequisites.OK.Ijustwanttophraseitasadivide-and-conquerbecauseyoudon'tnormallyseeitthatway.ThedividestepisyoucompareXwiththemiddleelementinyourarray.Thentheconquerstep.Hereisyourarray.Hereisthemiddleelement.
YoucompareXwiththisthingiflet'ssayXissmallerthanthemiddleelementinyourarray.YouknowthatXisinthelefthalfbecauseitissorted,aniceloopinvariantthere,whatever,butwearejustgoingtothinkofthatasrecursivelyIamgoingtosolvetheproblemoffindingXinthissubarray.Werecurseinonesubarray,unlikemergesortwherewehadtworecursions.Andthenthecombinedstepwedon'tdoanything.ImeanifyoufindXinherethenyou'vefoundXinthewholearray.Thereisnothingtobringitbackupreally.So,thisisjustphrasingbinarysearchinthedivide-and-conquerparadigm.Itiskindofatrivialexample,buttherearelotsofcircumstanceswhereyouonlyneedtorecurseinoneside.
Anditisimportanttoseehowmuchofadifferencemakingonerecursionversusmakingtworecursionscanbe.Thisistherecurrenceforbinarysearch.Westartwithaproblemsizen.Wereduceitto1.Thereisanimplicit1factorhere.Onesubproblemofsizenover2roughly.Again,floorsandceilingsdon'tmatter.PlusaconstantwhichistocompareXwiththemiddleelement,soitisactuallylikeonecomparison.
Thishasasolution,logn.Andyouallknowtherunningtimeofbinarysearch,buthereitisatsolvingtherecurrence.Imean,thereareacoupleofdifferenceshere.Wedon'thavetheadditiveordernterm.Ifwedid,itwouldbelinear,therunningthetime.Stillbetterthannlogn.So,wearegettingridofthe2,bringingitdowntoa1,takingthenan
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Transcript3