高级算法优质PPT.ppt

上传人:b****2 文档编号:15128428 上传时间:2022-10-27 格式:PPT 页数:32 大小:677.50KB
下载 相关 举报
高级算法优质PPT.ppt_第1页
第1页 / 共32页
高级算法优质PPT.ppt_第2页
第2页 / 共32页
高级算法优质PPT.ppt_第3页
第3页 / 共32页
高级算法优质PPT.ppt_第4页
第4页 / 共32页
高级算法优质PPT.ppt_第5页
第5页 / 共32页
点击查看更多>>
下载资源
资源描述

高级算法优质PPT.ppt

《高级算法优质PPT.ppt》由会员分享,可在线阅读,更多相关《高级算法优质PPT.ppt(32页珍藏版)》请在冰豆网上搜索。

高级算法优质PPT.ppt

BinarysearchFindanelementinasortedarray:

Divide:

Findandcheckthemiddleelement.Conquer:

Recursivelysearch1subarray.Combine:

Trivial.Example:

Find9BinarysearchFindanelementinasortedarray:

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 建筑土木

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1