高级算法.ppt
- 文档编号:2210563
- 上传时间:2022-10-27
- 格式:PPT
- 页数:32
- 大小:677.50KB
高级算法.ppt
《高级算法.ppt》由会员分享,可在线阅读,更多相关《高级算法.ppt(32页珍藏版)》请在冰豆网上搜索。
AdvancedAlgorithmsAnalysis&DesignNov.2014TodaysTasksDivideandConquerBinarySearchPoweringNumbersIndicatorRandomVariableThebirthdayparadoxFibonaccinumbersApplicationHowtocompute?
DivideandConquerDividetheproblemintosubproblems.Conquerthesubproblemsbysolvingthemrecursively.Combinesubproblemsolutions.Manyclassicalalgorithmsusethisparadigm.Givemeanexampleinsorting,please?
DivideandConquerTakeSortingasanexampleExam1:
BinarysearchFindanelementinasortedarray:
Divide:
Findandcheckthemiddleelement.Conquer:
Recursivelysearch1subarray.Combine:
Trivial.Example:
Find9BinarysearchFindanelementinasortedarray:
Divide:
Findandcheckthemiddleelement.Conquer:
Recursivelysearch1subarray.Combine:
Trivial.Example:
Find9BinarysearchFindanelementinasortedarray:
Divide:
Findandcheckthemiddleelement.Conquer:
Recursivelysearch1subarray.Combine:
Trivial.Example:
Find9BinarysearchFindanelementinasortedarray:
Divide:
Findandcheckthemiddleelement.Conquer:
Recursivelysearch1subarray.Combine:
Trivial.Example:
Find9BinarysearchFindanelementinasortedarray:
Divide:
Findandcheckthemiddleelement.Conquer:
Recursivelysearch1subarray.Combine:
Trivial.Example:
Find9BinarysearchFindanelementinasortedarray:
Divide:
Findandcheckthemiddleelement.Conquer:
Recursivelysearch1subarray.Combine:
Trivial.Example:
Find9ComplexityforbinarysearchT(n)=1T(n/2)+
(1)#subproblemssubproblemsizecostofdividingandcombiningRecallourMasterMethodSolverecurrencesoftheform:
T(n)=aT(n/b)+f(n),wherea1,b1,andf(n)isasymptoticallypositive.RecurrenceforbinarysearchT(n)=1T(n/2)+
(1)b=2,a=1Case2(k=0)#subproblemssubproblemsizecostofdividingandcombiningExam2:
PoweringaNumberProblem:
Computean,wherenN.Naivealgorithm:
How?
Complexity?
TheSpotCreativity:
Isthistheonlyandthebestalgorithm?
AnySuggestionsonusingdivide-and-conquerstrategy?
(n)Divide-and-conquer:
Complexity:
T(n)=T(n/2)+
(1)a=1,b=2=n0=1case2(k=0)T(n)=(lgn)PoweringaNumberTheBirthdayParadoxHowmanypeoplemusttherebeinaroomiftherearetwoofthemwerebornonthesamedayoftheyear?
Howmanypeoplemusttherebeinaroomifthereisabigchancethattwoofthemwerebornonthesameday?
Suchasprobabilityofmorethan50%?
IndicatorRandomVariableWeknowthattheprobabilityofisbirthdayandjsbirthdaybothfallonthesamedayris1/n,n=365WedefinetheindicatorrandomvariableXijfor1ijk,byIndicatorRandomVariableThuswehaveEXij=Prpersoniandjhavethesamebirthday=1/n.LettingXbetherandomvariablethatcountsthenumberofpairsofindividualshavingthesamebirthdayTheBirthdayParadoxIfwehaveatleastindividualsinaroom,wecanexpecttwotohavethesamebirthday.Forn=365,ifk=28,theexpectednumberofpairswiththesamebirthdayis(2827)/(2365)1.0356.FibonaccinumbersBackgroundofFibonacci0112358132134.GivemetherecursivedefinitionofFibonacciNumbers?
GivemeanapplicationofFibonaccinumbers.ApplicationofFibonacciThereisastaircaseof10steps,andyoucanstepacrossoneortwostepsasyoulikeeachtime.Howmanywayswehavetosteponthestage?
WhatstheratioofthetwoadjacentnumbersintheFibonacciSequence,thatstosay,whatsthevalueofFn-1/Fnwhenntendsto?
ElliottWavePrinciple:
KeytoMarketBehaviorQuestion:
HowcanwecomputeFibonacciasfastaspossibleincomputer?
NavealgorithmofFibonacciTocomputerFibonaccinumberFn=Fn-1+Fn-2Howmuchtimedoesittake?
SubstitutionmethodRecursion-treemethodMastermethodRecallSubstitutionmethodThemostgeneralmethodGuesstheformofthesolution.Verifybyinduction.Solveforconstants.Substitutionmethodisusedtodeterminetheupperorlowerboundsofrecurrence.AnalyzeofFibonacciTocomputerFibonaccinumberFn=Fn-1+Fn-2Howmuchtimedoesittake?
SubstitutionmethodRecursion-treemethodMastermethodSubstitutionmethodGuessO(2n)Guess=T(n)=Infact,T(n)=(1.618)nQuestionsWhythisrecursivealgorithmtakessomuchtime?
BuildingouttherecursiontreeforF(n),wecanseethattherearelotsofcommonsubtrees.ToomanyduplicationsthatwastetimeImportantinRecursionCompoundInterestRuleCanweimprovethisalgorithm?
Thinkaboutthebottom-upimplantationofthisrecursivealgorithmComputetheFibonaccinumbersinorder.IterativeTocomputerFibonaccinumberF(n),Howmuchtimedoesittake?
T(n)=(n)Isthatthebestwecando?
AnyideasonhowwecouldcomputeFibonacciofnfasterthanlineartime?
UsingmathematicalpropertiesofFibonaccinumbersroundedtothenearestinteger,whereWhatwecallNaiverecursivesquaring.TimeComplexity:
Doesthisworkwell?
Thismethodisunreliable,sincefloating-pointarithmeticispronetoround-offerrors.RecursiveSquaringAnothermathematicalpropertyofFibonaccinumbersProofofTheoremRecursiveSquaringAnothermathematicalpropertyofFibonaccinumbersWhatsthecostofcomputingFn?
HomeworkCode
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 高级 算法