1. 1、本文档共39页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Camp;ndash;CYao.ppt

C. –C. Yao Step Count of Fibonacci Program Two cases: n = 0 or n = 1 Line 4 regarded as two lines: 4(a) and 4(b), total step count in this case is 2 n 1 Line 4(a), 6, and 13 are each executed once Line 7 gets executed n times. Lines 8 – 12 get executed n-1 times each. Line 6 has s/e of 2 and the remaining lines have an s/e of 1. Total steps for the case n 1 is 4n + 1 C. –C. Yao Asymptotic Notation Determining step counts help us to compare the time complexities of two programs and to predict the growth in run time as the instance characteristics change. But determining exact step counts could be very difficult. Since the notion of a step count is itself inexact, it may be worth the effort to compute the exact step counts. Definition [Big “oh”]: f(n) = O(g(n)) iff there exist positive constants c and n0 such that f(n) ≤ cg(n) for all n, n ≥ n0 C. –C. Yao Examples of Asymptotic Notation 3n + 2 = O(n) 3n + 2 ≤ 4n for all n ≥ 3 100n + 6 = O(n) 100n + 6 ≤ 101n for all n ≥ 10 10n2 + 4n + 2 = O(n2) 10n2 + 4n + 2 ≤ 11n2 for all n ≥ 5 C. –C. Yao Asymptotic Notation (Cont.) Theorem 1.2: If f(n) = amnm + … + a1n + a0, then f(n) = O(nm). Proof: for n ≥ 1 So, f(n) = O(nm) C. –C. Yao Asymptotic Notation (Cont.) Definition: [Omega] f(n) = Ω(g(n)) iff there exist positive constants c and n0 such that f(n) ≥ cg(n) for all n, n ≥ n0. Example: 3n + 2 = Ω(n) 100n + 6 = Ω(n) 10n2 + 4n + 2 =Ω(n2) C. –C. Yao Asymptotic Notation (Cont.) Definition: f(n) = Θ(g(n)) iff there exist positive constants c1, c2, and n0 such that c1g(n) ≤ f(n) ≤ c2g(n) for all n, n ≥ n0. C. –C. Yao Asymptotic Notation (Cont.) Theorem 1.3: If f(n) = amnm + … + a1n + a0 and am 0, then f(n) = Ω(nm). Theorem 1.4: If f(n) = amnm + … + a1n + a0 and am 0, then f(n) = Θ(nm). C. –C. Yao Practical Complexities If a program P has complexities Θ(n) and program Q has complexities Θ(n2), then, in general, we can assume program P is faster than Q for a sufficient large n.

文档评论(0)

fa159yd + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档