Amortized AnalysisA-PDF Text Replace DEMO: Purchase from to remove the watermark
10/18/2012: Amortized Analysis2Amortized Analysis•Not just consider one operation, but a sequence of operations on a given data structure.•Average cost over a sequence of operations.•Probabilistic analysis:–Average case running time: average over all possible inputs for one algorithm (operation).–If using probability, called expected running time. •Amortized analysis:–No involvement of probability–Average performance on a sequence of operations, even some operation is expensive.–Guarantee average performance of each operation among the sequence in worst case.
10/18/2012: Amortized Analysis3Three Methods of Amortized Analysis•Aggregate analysis:–Total cost of noperations/n,•Accounting method:–Assign each type of operation an (different) amortized cost–overcharge some operations, –store the overcharge as credit on specific objects, –then use the credit for compensation for some later operations.•Potential method:–Same as accounting method–But store the credit as “potential energy” and as a whole.
10/18/2012: Amortized Analysis4Example for amortized analysis•Stack operations:–PUSH(S,x), O(1)–POP(S), O(1)–MULTIPOP(S,k), min(s,k)•while not STACK-EMPTY(S) and k>0•do POP(S)•k=k-1•Let us consider a sequence of nPUSH, POP, MULTIPOP.–The worst case cost for MULTIPOP in the sequence is O(n), since the stack size is at most n. –thus the cost of the sequence is O(n2). Correct, but not tight.
10/18/2012: Amortized Analysis5Aggregate Analysis In fact, a sequence of noperations on an initially empty stack cost at most O(n). Why?Each object can be POP only once for each time it is PUSHed.