版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
GrowthofFunctions(函数增加)2/10/10CollegeofComputerScience&Technology,BUPTTheGrowthofFunctionsWequantifytheconceptthatg
growsatleastasfastasf.Whatreallymattersincomparingthecomplexityofalgorithms?Weonlycareaboutthebehaviorforlarge
problems.Evenbadalgorithmscanbeusedtosolvesmallproblems.Ignoreimplementationdetailssuchasloopcounterincrementation,etc.Wecanstraight-lineanyloop.3/10/10CollegeofComputerScience&Technology,BUPTOrdersofGrowth(§3.2)Forfunctionsovernumbers,weoftenneedtoknowaroughmeasureofhowfastafunctiongrows.Iff(x)isfastergrowingthang(x),thenf(x)alwayseventuallybecomeslargerthang(x)inthelimit(forlargeenoughvaluesofx).Usefulinengineeringforshowingthatonedesignscalesbetterorworsethananother.4/10/10CollegeofComputerScience&Technology,BUPTOrdersofGrowth-MotivationSupposeyouaredesigningawebsitetoprocessuserdata(e.g.,financialrecords).SupposedatabaseprogramAtakesfA(n)=30n+8microsecondstoprocessanynrecords,whileprogramBtakesfB(n)=n2+1microsecondstoprocessthenrecords.Whichprogramdoyouchoose,knowingyou’llwanttosupportmillionsofusers?A5/10/10CollegeofComputerScience&Technology,BUPTVisualizingOrdersofGrowthOnagraph,as
yougotothe
right,thefaster-
growingfunc-
tionalways
eventually
becomesthe
largerone...fA(n)=30n+8IncreasingnfB(n)=n2+1Valueoffunction6/10/10CollegeofComputerScience&Technology,BUPTConceptoforderofgrowthWesayfA(n)=30n+8
is(atmost)
ordern,orO(n).Itis,atmost,roughlyproportionalton.fB(n)=n2+1isordern2,orO(n2).Itis(atmost)roughlyproportionalton2.Anyfunctionwhoseexact(tightest)
orderisO(n2)isfaster-growingthananyO(n)function.LaterwewillintroduceΘforexpressingexactorder.Forlargenumbersofuserrecords,theexactlyordern2functionwillalwaystakemoretime.7/10/10CollegeofComputerScience&Technology,BUPTTheBig-ONotationDefinition:LetfandgbefunctionsfromNorRtoR.Theng
asymptoticallydominates(渐进地支配)f,denotedfisO(g)or'fisbig-Oofg,iff$k$c"n[n>k®|f(n)|£c|g(n)|]“fisatmostorderg”,or“fisO(g)”,or“f=O(g)”alljustmeanthatfO(g).Note:ChoosekChoosec;itmaydependonyourchoiceofkOnceyouchoosekandc,youmustprovethetruthoftheimplication(oftenbyinduction)8/10/10CollegeofComputerScience&Technology,BUPTPointsaboutthedefinitionNotethatfisO(g)solongasanyvaluesofcandkexistthatsatisfythedefinition.But:Theparticularc,k,valuesthatmakethestatementtruearenotunique:Anylargervalueofcand/orkwillalsowork.
Youarenotrequiredtofindthesmallestcandkvaluesthatwork.(Indeed,insomecases,theremaybenosmallestvalues!)However,youshouldprovethatthevaluesyouchoosedowork.9/10/10CollegeofComputerScience&Technology,BUPTlittle-oofgIncalculusIfThenfiso(g)(calledlittle-oofg)10/10/10CollegeofComputerScience&Technology,BUPTTheoremIffiso(g)thenfisO(g).Proof:bydefinitionoflimitasngoestoinfinity,f(n)/g(n)getsarbitrarilysmall.Thatisforanye>0,theremustbeanintegerNsuchthatwhenn>N,|f(n)/g(n)|<e.Hence,choosec=e
andk=N.Q.E.D.11/10/10CollegeofComputerScience&Technology,BUPTExample3n+5isO(n2)Proof:It'seasytoshowusingthetheoryoflimits.Hence3n+5iso(n2)andsoitisO(n2).Q.E.D.12/10/10CollegeofComputerScience&Technology,BUPTExample13/10/10CollegeofComputerScience&Technology,BUPT“Big-O”ProofExamplesShowthat30n+8isO(n).Showc,k:n>k:
30n+8cn.Letc=31,k=8.Assumen>k=8.Then
cn=31n=30n+n>30n+8,so30n+8<cn.Showthatn2+1isO(n2).Showc,k:n>k:n2+1cn2.Letc=2,k=1.Assumen>1.Then
cn2=2n2=n2+n2>n2+1,orn2+1<cn2.14/10/10CollegeofComputerScience&Technology,BUPTNote30n+8isn’t
lessthann
anywhere(n>0).Itisn’teven
lessthan31n
everywhere.Butitislessthan
31n
everywhereto
therightofn=8.n>k=8Big-Oexample,graphicallyIncreasingnValueoffunctionn30n+8cn=
31n30n+8
O(n)15/10/10CollegeofComputerScience&Technology,BUPTSomeimportantBig-OresultsTheorem1Letf(x)=anxn
+
an-1xn-1
+…+a1x+a0
,wherea0,
a1,
…an-1,an
arerealnumbers.Thenf(x)isO(xn).n!isO(nn)logn!isO(nlogn)lognisO(n)1,logn,n,nlogn,n2,2n,n!16/10/10CollegeofComputerScience&Technology,BUPTThegrowthofcombinationsoffunctionsTheorem2Supposethatf1isO(g1)andf2isO(g2).Thenf1+f2isO(max{g1,g2})Corollary1Iff1,f2arebothO(g)thenf1+f2isO(g).Theorem3Supposethatf1isO(g1)andf2isO(g2).Thenf1f2isO(g1g2)17/10/10CollegeofComputerScience&Technology,BUPTProofoff1f2isO(g1g2)Thereisak1andc1suchthat1.f1(n)<c1g1(n)whenn>k1.Thereisak2andc2suchthat2.f2(n)<c2g2(n)whenn>k2.Wemustfindak3andc3suchthat3.f1(n)f2(n)<c3g1(n)g2(n)whenn>k3.18/10/10CollegeofComputerScience&Technology,BUPTProofoff1f2isO(g1g2)Weusetheinequalityif0<a<band0<c<dthenac<bdtoconcludethatf1(n)f2(n)<c1c2g1(n)g2(n)aslongask>max{k1,k2}sothatbothinequalities1and2.holdatthesametime.Therefore,choosec3=c1c2andk3=max{k1,k2}.Q.E.D.19/10/10CollegeofComputerScience&Technology,BUPTExampleFindthecomplexityclassofthefunction(nn!+3n+2
+3n100)(nn
+n2n
)Solution:Thismeanstosimplifytheexpression.Throwoutstuffwhichyouknowdoesn'tgrowasfast.Andatlast:nn!nn20/10/10CollegeofComputerScience&Technology,BUPTBig-omeganotationDefinition:LetfandgbefunctionsfromNorRtoR.Wesayfis(g)or'fisbig-ofg,'iff$k$c"n[n>k®|f(n)|c|g(n)|]Note:ChoosekChoosec;itmaydependonyourchoiceofkOnceyouchoosekandc,youmustprovethetruthoftheimplication(oftenbyinduction)21/10/10CollegeofComputerScience&Technology,BUPTBig-thetanotationIffO(g)andgO(f),thenwesay“gandfareofthesameorder”or“fis(exactly)orderg”andwritef(g).Another,equivalentdefinition:
(g){f:RR|
c1c2k>0x>k:|c1g(x)||f(x)||c2g(x)|}“Everywherebeyondsomepo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- (新教材)2026年青岛版八年级上册数学 1.3 几何证明举例 课件
- (新教材)2026年沪科版七年级上册数学 5.1 数据的收集 课件
- 2025-2026学年广东省广州市越秀区执信中学高三(上)期中地理试卷
- 大丰市小海中学高二生物三同步课程讲义第讲神经系统的调节(三)
- 2025年办公室装修安全责任合同协议
- 第5课罗马城邦和罗马帝国习题课件
- 多尺度服务权衡关系
- 2025硫磺行业深度报告-全球供需矛盾突出硫磺价格有望上行
- 2026 年中职康复技术(理疗设备操作)试题及答案
- 螺栓受力分析试题及答案
- 常见的胃肠道疾病预防
- 2024-2025学年江苏省徐州市高一上学期期末抽测数学试题(解析版)
- 新解读《DL-T 5891-2024电气装置安装工程 电缆线路施工及验收规范》新解读
- 生产部装配管理制度
- DB31/T 1205-2020医务社会工作基本服务规范
- 酒店供货框架协议书
- 纺织品的物理化学性质试题及答案
- 高处安装维护拆除作业培训
- 长鑫存储在线测评
- 2025年小学生科普知识竞赛练习题库及答案(200题)
- (完整版)保密工作奖惩制度
评论
0/150
提交评论