版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 13961-2026灯具用电源导轨系统
- 消防安全隐患拆除通知
- 安全生产年限证明讲解
- 超市消防安全现状分析
- 社区团长招募与活跃提升工具包邀约分工激励
- 2026年10月自考14616园林植物应用设计(江苏)押题及答案
- 公司印信管理规定
- 法律职业资格客观题真题汇编冲刺(解析版)
- 关于年度销售指标完成情况确认函(4篇)
- 办公室装修合同确认函模板(3篇范文)
- 2026年新教材八年级上册历史全册必背知识点考点提纲
- 2026年湖北专升本汉语言文学专业(现代汉语中国古代文学)题库附答案
- 2026年四川省拟任县处级领导干部理论(任职资格考试)全真模拟试题及答案
- SD22推土机使用说明书完整版
- 2026潍坊第二人民医院招聘(3人)建设笔试备考试题及答案解析
- 湖北省荆州市松滋市2025-2026学年上学期八年级物理期末试题(含答案)
- 社区食堂规范运营制度范本
- 2026年深圳市离婚协议书规范范本
- GB/T 21873-2025橡胶密封件给、排水管及污水管道用接口密封圈材料规范
- 神经内科疾病康复与治疗
- 公共资源交易数据的价值与应用分析
评论
0/150
提交评论