网站大量收购独家精品文档,联系QQ:2885784924

盈亏均摊之分析方式.pdf

  1. 1、本文档共20页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Amortized Analysis 盈虧均攤之分析方式 名詞:amortized analysis ,worst case analysis Average case analysis —aggregate method 硬功夫累計法 —accounting method 銀行會計(記帳)法 —potential method 要體會這些名詞背後之觀念,最好還是看些例子,通常是針對”a sequence of operations” 的problem ,要算它的time complexity 例: p452 a stack S 假設我們要處理一個data structure : a stack S 而要做一連串的PUSH,POP 動作 為了彰顯問題所在,以下我們考慮會做三種operations: —PUSH(S,x) 把x 放在stack S 最”上”面 —POP(S) 把stack S 最”上”面的object pop 出來 —MULTIPOP(S,k) 把S”上”面k 個objects 都pop 出來 (看p452) Time complexity ? 作一次 Push operation O(1) 一次 Pop O(1) 一次 Multipop O(min ( |S| , k )) 若作” a sequence of operations (mixed with push, pop, multi pop) on an initially empty stack)” Time complexity ? total T(n)=? Each operation =? 在早期(1970 年代以前) 大家都是考慮worst case analysis (也有一些average case analysis ,不過這牽涉到probability 的理論假設) 而amortized analysis 完全不牽涉到 probability (可說是worst case!)用worst case analysis 來看此例: 在worst case 時,作一次multipop 需O(n), 因stack 中可能有O(n)個elements 作 a sequence of operations 在worst case 時,可能 multipop 會佔很大的比率,O(n) 次 的multipop 每一次O(n) time ⇒作a sequence of operations 在worst case 時 Total time T(n)=O(n2) Each operation = O(n) 1 以上這樣的worst case analysis 其分析的過程及結果都相當鬆散,以致於得到的 不是一個tight bound 。 等一下會看到用深入一點的分析,會得到一個tight bound ⇒T(n) = O(n) 而 = O(1) 註:等一下會看到 T(n) = O(n) 是一個worst case time bound 而 =O(1) 並不是說 each operation 在worst case 時只需O(1)time. 而是average performance of each operation in the worst case Reference: R.E. Tarjan”Amortized computational complexity ” SIAM J.on Algebraic and Diserete Methods 6(2) p.306-318 1985 再看一個例子:incrementing a binary counter p.454 有一個k-bit binary counter 它從0 開始往上計時(計數) 0,1,2,3,4,5… 實際implementing 軟體時,有一個k-bit array 在作此事 見課本p455 Figure 17

文档评论(0)

管理学科 + 关注
实名认证
内容提供者

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

1亿VIP精品文档

相关文档