版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Algorithms Design and Analysis:Amortized AnalysisProf. Dr. Jinxing XieDept. of Mathematical SciencesTsinghua University, Beijing 100084, China Voice:(86-10)62787812 Fax:(86-10)62785847What is an amortized analysis? The time required to perform a sequence of data-structure operations is averaged over
2、 all the operations performed. Used to show the average cost of an operationA sequence of operationstimeaverageAmortized Analysis Differs from average-case analysis: Probability is not involved; Guarantees the average performance of each operation in the worst case Three techniques: Aggregate analys
3、is Accounting method Potential methodExample:Increasing a k-bit binary counterIncreasing a k-bit binary counterImplementing a k-bit binary counter that counts upward from 0: A0.k-1 for bits, where lengthA=k. x: lowest-order bit in A0 and highest-order bit in Ak-1 Initially, assume x=0 Aggregate anal
4、ysis A sequence of n operations takes worst-case time T(n) in total Amortized cost per operation, in the worst case, is T(n)/nThe algorithmFirst glance:(Worst case) Each time: Total: O(nk)Can we do better?Aggregate analysis:Average cost per operationA0: flips each timeA1: flips every other timeA2: f
5、lips every fourth timeAk-1: flips every 2k-1-th timeFor a sequence of n INCREMENTs:Average cost (amortized cost) per operation:The accounting methodAssign differing charges (amortized cost) to different operations, with some operations charged more or less than they actually cost. When an operations
6、 amortized cost exceeds its actual cost, the difference is assigned to specific objects in the data structure as credit.Credit can be used later on to help pay for operations whose amortized cost is less than their actual cost.Attention: Total credit stored in the data structure should never es nega
7、tive!Assume flipping a bit costs a dollar:Charge an amortized cost of 2 dollars to set a bit to 1Credit on “1”: 1 dollarExample: INCREMENTWhen a bit is set, we use 1 dollar to pay for the actual setting of the bit, and place the other dollar on the bit as credit to be used later when we flip the bit
8、 back to 0.Every “1” has a dollar of credit on it, thus we need not charge anything to rest a bit to 0Credit never es negative!In each operation, at least one bit is set: cost 2 dollarsTotal cost for n operations: O(n)Potential methodRepresents the prepaid work as “potential energy” or just “potenti
9、al”, that can be released to pay for future operations. The potential is associated with the data structure as a whole rather than with specific objects within the data structureInitial data structure: D0For each i=1,2,n, let ci be the actual cost of the ith operation and Di be the data structure af
10、ter applying the ith operation to data structure Di-1Potential function:Amortized cost: Example: INCREMENTDefine the potential function: bi = the number of 1s in the counter after the ith operationSuppose the ith operation resets ti bits (to 0)The actual cost of the operation is at most ci 0, then b
11、i = bi-1 - ti +1bi = 0.5) TableTTABLE-INSERTElementary insertion: cost=1Initial Analysis for n consecutive insertions (starting with an empty table)ith insertion costs ci:- If there is room in current table (or its the first operation), ci=1 If the table is full, need (i-1) copies (insertions), ci=i
12、 In worst-case, an operation costs O(n)Totally O(n2)Full tablenew tablecopyxAggregate AnalysisTotallyAverage cost of an operation: O(1)Charge each insertion 3dollars:- One for the current insertion;- The second for the immediate moving of itself when the table is expanded The third is for the item a
13、lready moved onceWhen the table is full, each item has a dollar to pay for its reinsertion during the expansionAccounting AnalysisCharge each insertion 3dollars:- One for the current insertion;- The second for the immediate moving of itself when the table is expanded The third is for the item alread
14、y moved onceWhen the table is full, each item has a dollar to pay for its reinsertion during the expansionPotential methodNonnegative: numT = sizeT /2Immediately after an expansion: Immediately before an expansion:Potential methodLet numi denote numT after ith insertion Let sizei denote sizeT after
15、ith insertionIf the ith insertion does not trigger an expansion:If the ith insertion does trigger an expansion:Both Insertion & DeletionInsertion can cause expansion of the tableDeletion can cause contraction of the table Contract whenever load factor 0.5? numT=4 1 2 3 4 5 6 7 8 sizeT=8 load factor=
16、0.5TableTdeleteTableTdeleteNew tableContract whenever load factor 0.5First n/2 insertions, where n is an exact power of 2The following n/2 operations: I, D, D, I ,I, D, D, I, I, The cost of each expansion or contraction is Totally Amortized cost of an operationTableTTableTdeleteTableTContract whenev
17、er deleting at load factor = The contraction assure that the load factor is 1? - No! Its not a good idea! - Halve the table size maybe better (load factor 1/2)Whats the complexity of a sequence of n insertions and deletions? - Really challenging !TableTTableTTABLE-DELETEElementary deletion: cost=1Po
18、tential method When load factor=1, i.e. numT=sizeT, thus potential=numT can pay for an expansion if an item is inserted When load factor=1/4, i.e. sizeT=4*numT, thus potential=numT can pay for a contraction if an item is deleted Contract whenever deleting at load factor = When the operation is insertion:After ith operationIf Identical to previous discussionIfIfContract whenever deleting at load factor = When the operation is deletion:After ith operationIfIfContract wheneve
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 吉林大學(xué)《組織行為學(xué)A》2021-2022學(xué)年第一學(xué)期期末試卷
- 吉林大學(xué)《現(xiàn)代控制理論基礎(chǔ)》2021-2022學(xué)年期末試卷
- 中秋節(jié)校外實(shí)踐活動(dòng)方案
- 2024員工試用合同
- 健身房裝修合同補(bǔ)充條款協(xié)議書(shū)
- 農(nóng)業(yè)科技實(shí)習(xí)生協(xié)議書(shū)
- 吉林大學(xué)《數(shù)字集成電路設(shè)計(jì)》2021-2022學(xué)年期末試卷
- 吉林大學(xué)《農(nóng)經(jīng)前沿專(zhuān)題》2021-2022學(xué)年第一學(xué)期期末試卷
- 高層建筑安全節(jié)能管理策略
- 科學(xué)實(shí)驗(yàn)室護(hù)學(xué)崗安全管理制度
- 2022屆江蘇省無(wú)錫市高三上學(xué)期期中教學(xué)質(zhì)量調(diào)研測(cè)試英語(yǔ)試題(教師版含解析)
- 《中成藥的應(yīng)用》課件
- 設(shè)備包機(jī)到人管理制度
- 初中英語(yǔ)-現(xiàn)在進(jìn)行時(shí) 過(guò)去進(jìn)行時(shí)(含練習(xí))
- 中小學(xué)校財(cái)務(wù)管理案例分析
- 《我們小點(diǎn)兒聲》評(píng)課報(bào)告
- 企業(yè)經(jīng)營(yíng)模擬實(shí)訓(xùn)知到章節(jié)答案智慧樹(shù)2023年華南農(nóng)業(yè)大學(xué)
- (完整版)全國(guó)各省份城市明細(xì)表
- 膽總管囊腫護(hù)理查房
- GB/T 30475.2-2013壓縮空氣過(guò)濾器試驗(yàn)方法第2部分:油蒸氣
- GB/T 25217.13-2019沖擊地壓測(cè)定、監(jiān)測(cè)與防治方法第13部分:頂板深孔爆破防治方法
評(píng)論
0/150
提交評(píng)論