版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
2023/4/241ReviewoflastclassHowtosolveaproblembycomputerThenotionofalgorithmActualproblemMathematicsmodelAlgorithmdesignandanalysisProgrammingResultanalysisInputoutputfinitenesseffectivenessdefinitenessAlgorithmdesignpattern2023/4/242Howtodescribeanalgorithm?NaturallanguageStep1Inputmandn.Step2Dividembynandassignthevalueoftheremaindertor.Step3Ifr=0,returnthevalueofnastheanswerandstop;otherwise,proceedtoStep4.Step4Assignthevalueofntomandthevalueofrton.Step5GotoStep2.Advantages:easyunderstandDisadvantages:existinherentambiguity2023/4/243Howtodescribeanalgorithm?(II)FlowchartStartr=0Inputmandnr=m%nm=nn=routputnStopAflowchartisamethodofexpressinganalgorithmbyacollectionofconnectedgeometricshapescontainingdescriptionsofthealgorithm’ssteps.Advantages:intuitiveDisadvantages:lackflexibility2023/4/244Howtodescribeanalgorithm?(III)ProgramminglanguageAdvantages:canrunoncomputerdirectlyDisadvantages:lackabstraction#include<iostream.h>intGCD(intm,intn){
intr=m%n;
while(r!=0) { m=n; n=r; r=m%n; }
returnn;}voidmain(void){ cout<<GCD(60,24)<<endl;}2023/4/245Howtodescribeanalgorithm?(IV)Pseudocode1r=m%n;2Whiler≠02.1m=n;2.2n=r;2.3r=m%n;3returnn;Advantages:moreprecisethannaturallanguageApseudocodeisamixtureofanaturallanguageandprogramminglanguage.Itusesthebasicgrammarofprogramminglanguage,buttheoperationinstructionscandesignedwithnaturallanguage.Disadvantages:notexistasingleformofpseudocode2023/4/246FundamentalsoftheAnalysisofAlgorithmEfficiency(I)Chapter21、Theframeworktoanalyzealgorithms
2、Best,worst,average-caseanalysis
3、Threeasymptoticnotations2023/4/247GoalsofthislectureAttheendofthislecture,youshouldbeabletoDescribehowtoanalyzeanalgorithmUnderstandwhatisabest-case,worse-caseandaverage-caseanalysisMasterthethreeasymptoticnotations,,O,rateofgrowth2023/4/248AnalysisofalgorithmsDefinition:
Algorithmanalysismeanstoevaluatethetwocomputerresources,timeandspace,whichneededbyanalgorithm.Lessresourcesanalgorithmneeds,moreefficiencyitis.
Issues:timeefficiencyDeterminestheamountoftimethatalgorithmneedstobeexecuted.spaceefficiencyDeterminestheamountofspacethatalgorithmneedstobeexecuted.Approaches:
theoreticalanalysisempiricalanalysis2023/4/249Goal:DeterminestheamountoftimethatanalgorithmneedstobeexecutedMethods:DeterminestheexactamountoftimethatanalgorithmneedstobeexecutedDeterminesthenumberofrepetitionsofalltheoperationsasafunctionofinputsizeandinputinstanceWhereNistheinputsize,Iistheinputinstance.Theoreticalanalysisoftimeefficiency2023/4/2410OperationsComparisonsEqual,greater,notequal,…LogicaloperationsAnd,or,xor,not,…ArithmeticoperationsAdditions:add,subtract,increment,decrementMultiplications:multiply,divide,modAssignmentoperationX=1Forconvenience,eachelementaryoperationisconsideredtouse1timeunit.2023/4/2411SizeofInputSortingandFindingproblems:numberofelementinthearrayortableGraphalgorithms:numberofverticesoredges,orsumofbothComputationalGeometry:usuallynumberofpoints,vertices,edges,linesegments,orpolygons.MatrixOperation:dimensionofmatrixNumbertheoryandcryptography:numberofbitsofinputnumber2023/4/2412Examplesxx+1for
j1to
n
doxx+1repeatT(N,I)=3nnadditions,2nassignmentsT(N,I)=21addition,1assignmentfor
i1to
n
do
for
j1to
n
do
xx+1
repeatrepeatT(n)=3n2+nn2additions,2n2+nassignments2023/4/2413TheoreticalanalysisoftimeefficiencyDeterminingthenumberofrepetitionsofthebasicoperationasafunctionofinputsizeandinputinstanceBasicoperation:theoperationthatcontributesmosttowardstherunningtimeofthealgorithm
T(N,I)≈copC(N,I)runningtimeexecutiontimeforbasicoperationNumberoftimesbasicoperationisexecutedinputsize,inputinstance2023/4/2414InputsizeandbasicoperationexamplesBasicoperationInputsizemeasureProblemVisitingavertexortraversinganedge#verticesand/oredgesTheshortestpathproblemMultiplicationoftwonumbersMatrixdimensionsortotalnumberofelementsMultiplicationoftwomatricesKeycomparisonNumberoflist’sitems,i.e.nSearchingforkeyinalistofnitems2023/4/2415BestCaseAnalysisLeastamountofworktobedoneoverallofthepossibleinputwiththesamesizeWorstCaseAnalysis(mostimportant!)MostamountofworktobedoneoverallofthepossibleinputwiththesamesizeBest-case,average-case,worst-case2023/4/2416AverageCaseAnalysisTheamountofworkaveragedoverallofthepossibleinputsetswiththesamesizeNOTtheaverageofworstandbestcaseBest-case,average-case,worst-case(II)2023/4/2417Example:SequentialsearchWorstcaseBestcaseAveragecase2023/4/2418RateofGrowth(Important)Therateofgrowthofafunctiondetermineshowfastthefunctionvalueincreaseswhentheinputincrease2023/4/2419RateofGrowthThefunctionx3growsfasterthanthefunctionx2IfalgorithmAdoesx3operationsonaninputofsizexandalgorithmBdoesx2operations,algorithmBismoreefficientBecauseoftherelativeratesofgrowthoffunctions,wewillconsiderthefunctions
x3+x2+xequivalenttox3(thereasonisthatwhenxislarge,thedifferencebetweenthemislittle,soweonlykeeptheitemthatgrowsfastestwhileomitothers)2023/4/2420ClassificationofGrowthBigOmega?(f):Theclassoffunctionsthatgrowatleastasfastasthefunctionf,andmaybefasterBigOhO(f):Theclassoffunctionsthatgrownofasterthanf,andmaybeslowerBigTheta(f)Theclassoffunctionsthatgrowatthesamerateasthefunctionf2023/4/2421AsymptoticNotation:O(mostimportant!)O-notation:asymptoticupperboundCallf(n)=O(g(n))ifthereexistpositiveconstantscandn0suchthat0f(n)cg(n)forallnn0.Or,if,thenf(n)=O(g(n))f(n)=2n3+3n-5
=O(n3)f(n)=2n3+3n-5
=
O(n4)Intheanalysisliterature,f(n)=
O(g(n))meansf(n)O
(g(n))Thinking:2n=O(2n+1)?2n+1=O(2n)?(logn)2=O(n)? (n+1)!=O(n!)2023/4/2422AsymptoticNotation:Onf(n)cg(n)n0f(n)=O(g(n))2023/4/2423AsymptoticNotation:-notation:asymptoticlowerboundCallf(n)=(g(n))ifthereexistpositiveconstantscandn0suchthat0cg(n)f(n)
forallnn0.or,if,thenf(n)=(g(n))f(n)=2n3+3n-5
=
(n3)f(n)=2n3+3n-5
=
(n2)Intheanalysisliterature,f(n)=
(g(n))meansf(n)
(g(n))2023/4/2424AsymptoticNotation:ncg(n)f(n)n0f(n)=(g(n))2023/4/2425Somepropertiesofasymptoticorderofgrowthf(n)O(f(n))
f(n)O(g(n))iffg(n)(f(n))
Iff
(n)O(g
(n))andg(n)O(h(n)),thenf(n)O(h(n))
Iff1(n)O(g1(n))andf2(n)O(g2(n)),thenf1(n)+
f2(n)O(max{g1(n),g2(n)})2023/4/2426AsymptoticNotation:-notation:
Callf(n)=(g(n))ifthereexistpositiveconstantsc1,c2,andn0suchthat0c1g(n)f(n)c2g(n)forallnn0.or,if,cisaconstantandc
>0,thenf(n)=(g(n))f(n)=2n3+3n-5
=(n3)f(n)=2n4+1=(n3)???2023/4/2427AsymptoticNotation:f(n)=(g(n))nf(n)c2g(n)n0c1g(n)2023/4/2428OrdersofgrowthofsomeimportantfunctionsAlllogarithmicfunctionslogan
belongtothesameclass
(logn)nomatterwhatthelogarithm’sbasea>1is
Allpolynomialsofthesamedegreekbelongtothesameclass:
aknk+ak-1nk-1+…+a0(nk)
Exponentialfunctionsanhavediffe
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025戶外品牌探路者線上新媒體運營方案
- 田徑運動會活動方案(匯編15篇)
- 五年級二十年后的家鄉(xiāng)單元作文
- 安全工作演講稿匯編15篇
- 2023年幼兒園安全工作計劃10篇
- 財務(wù)會計個人辭職報告集合8篇
- 一次有趣的游戲初一日記400字5篇
- 北京市通州區(qū)2024-2025學(xué)年八年級上學(xué)期期末考試道德與法治試卷(含答案)
- 2025年工程瑞雷波儀項目合作計劃書
- 國培計劃心得體會
- 統(tǒng)編版(2024新版)七年級上冊道德與法治期末綜合測試卷(含答案)
- 文化創(chuàng)意合作戰(zhàn)略協(xié)議
- (T8聯(lián)考)2025屆高三部分重點中學(xué)12月第一次聯(lián)考評物理試卷(含答案詳解)
- 中國慢性冠脈綜合征患者診斷及管理指南2024版解讀
- 駕駛艙資源管理緒論課件
- 聲藝 EPM8操作手冊
- 西北農(nóng)林科技大學(xué)專業(yè)學(xué)位研究生課程案例庫建設(shè)項目申請書(MBA)
- 外墻保溫、真石漆施工技術(shù)交底
- 尾礦庫在線監(jiān)測方案)
- 房屋安全簡易鑒定表.docx
- 警察公安工作匯報ppt模板ppt通用模板課件
評論
0/150
提交評論