Amortized Analysis Not just consider one operation, but a sequence of operations on a given data structure. Average cost over a sequence of operations.

Slides:



Advertisements
Similar presentations
October 31, 2005Copyright © by Erik D. Demaine and Charles E. LeisersonL13.1 Introduction to Algorithms LECTURE 11 Amortized Analysis Dynamic tables.
Advertisements

Amortized Analysis Some of the slides are from Prof. Leong Hon Wais resources at National University of Singapore Prof. Muhammad Saeed.
CS 473Lecture X1 CS473-Algorithms I Lecture X Dynamic Tables.
Single Source Shortest Paths
Analysis Of Binomial Heaps. Operations Insert  Add a new min tree to top-level circular list. Meld  Combine two circular lists. Remove min  Pairwise.
CSE332: Data Abstractions Lecture 21: Amortized Analysis Dan Grossman Spring 2010.
Advanced Data Structures Sartaj Sahni
Kinds Of Complexity Worst-case complexity. Average complexity. Amortized complexity.
UMass Lowell Computer Science Graduate Analysis of Algorithms Prof. Karen Daniels Spring, 2010 Lecture 3 Tuesday, 2/9/10 Amortized Analysis.
CPSC 411, Fall 2008: Set 6 1 CPSC 411 Design and Analysis of Algorithms Set 6: Amortized Analysis Prof. Jennifer Welch Fall 2008.
UMass Lowell Computer Science Graduate Analysis of Algorithms Prof. Karen Daniels Spring, 2005 Lecture 3 Tuesday, 2/8/05 Amortized Analysis.
Analysis Of Binomial Heaps. Operations Insert  Add a new min tree to top-level circular list. Meld  Combine two circular lists. Delete min  Pairwise.
Tirgul 9 Amortized analysis Graph representation.
UMass Lowell Computer Science Graduate Analysis of Algorithms Prof. Karen Daniels Spring, 2009 Lecture 3 Tuesday, 2/10/09 Amortized Analysis.
Amortized Anaysis of Algorihms, A.Yazici, Spring 2007CEng Amortized Analysis of Algorithms Adnan YAZICI Dept. of Computer Engineering Middle East.
Amortized Analysis (chap. 17) Not just consider one operation, but a sequence of operations on a given data structure. Average cost over a sequence of.
Amortized Analysis.
CS333 / Cutler Amortized Analysis 1 Amortized Analysis The average cost of a sequence of n operations on a given Data Structure. Aggregate Analysis Accounting.
Andreas Klappenecker [based on the slides of Prof. Welch]
Data Structure Algorithm Analysis TA: Abbas Sarraf
17.Amortized analysis Hsu, Lih-Hsing. Computer Theory Lab. Chapter 17P.2 The time required to perform a sequence of data structure operations in average.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 2 (Part 2) Tuesday, 9/11/01 Amortized Analysis.
CSE332: Data Abstractions Lecture 26: Amortized Analysis Tyler Robison Summer
1 Summary of lectures 1.Introduction to Algorithm Analysis and Design (Chapter 1-3). Lecture SlidesLecture Slides 2.Recurrence and Master Theorem (Chapter.
Ajinkya Nene, Lynbrook CS Club. 04/21/2014. Definition Allows you to figure the worst-case bound for the performance of an algorithm (most useful for.
CS 473Lecture 121 CS473-Algorithms I Lecture 12 Amortized Analysis.
Interval Trees.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 14 Prof. Charles E. Leiserson.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 5: Advanced Design Techniques.
1 Summary of lectures 1.Introduction to Algorithm Analysis and Design (Chapter 1-3). Lecture SlidesLecture Slides 2.Recurrence and Master Theorem (Chapter.
Amortized Analysis The problem domains vary widely, so this approach is not tied to any single data structure The goal is to guarantee the average performance.
Amortized Complexity Aggregate method. Accounting method. Potential function method.
Amortized Analysis Typically, most data structures provide absolute guarantees on the worst case time for performing a single operation. We will study.
TECH Computer Science Dynamic Sets and Searching Analysis Technique  Amortized Analysis // average cost of each operation in the worst case Dynamic Sets.
CS 361 – Chapter 1 What is this class about? –Data structures, useful algorithm techniques –Programming needs to address both –You already have done some.
1 Chapter 17: Amortized Analysis I. 2 About this lecture Given a data structure, amortized analysis studies in a sequence of operations, the average time.
CSC401 – Analysis of Algorithms Lecture Notes 2 Asymptotic Analysis Objectives: Mathematics foundation for algorithm analysis Amortization analysis techniques.
Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2004 Simonas Šaltenis E1-215b
Amortized Analysis We examined worst-case, average-case and best-case analysis performance In amortized analysis we care for the cost of one operation.
Amortized Analysis Some of the slides are from Prof. Leong Hon Wai’s resources at National University of Singapore.
CSCE 411H Design and Analysis of Algorithms Set 6: Amortized Analysis Prof. Evdokia Nikolova* Spring 2013 CSCE 411H, Spring 2013: Set 6 1 * Slides adapted.
CMSC 341 Amortized Analysis.
David Luebke 1 12/12/2015 CS 332: Algorithms Amortized Analysis.
Amortized Analysis. p2. Amortized analysis: Guarantees the avg. performance of each operation in the worst case. Aggregate method Accounting method Potential.
Amortized Analysis. Problem What is the time complexity of n insert operations into an dynamic array, which doubles its size each time it is completely.
CSE373: Data Structures & Algorithms Lecture 8: Amortized Analysis Dan Grossman Fall 2013.
Introduction to Algorithms Amortized Analysis My T. UF.
Amortized Analysis In amortized analysis, the time required to perform a sequence of operations is averaged over all the operations performed Aggregate.
1 Chapter 17: Amortized Analysis II. 2 About this lecture Previous lecture shows Aggregate Method This lecture shows two more methods: (2)Accounting Method.
Introduction to Algorithms: Amortized Analysis. Introduction to Algorithms Amortized Analysis Dynamic tables Aggregate method Accounting method Potential.
Amortized Analysis.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Andreas Klappenecker [partially based on the slides of Prof. Welch]
Complexity analysis.
Amortized Analysis (chap. 17)
Summary of lectures Introduction to Algorithm Analysis and Design (Chapter 1-3). Lecture Slides Recurrence and Master Theorem (Chapter 4). Lecture Slides.
CSCE 411 Design and Analysis of Algorithms
Analysis Of Binomial Heaps
Chapter 17: Amortized Analysis I
Presentation by Marty Krogel
Amortized Analysis The problem domains vary widely, so this approach is not tied to any single data structure The goal is to guarantee the average performance.
Chapter 17 Amortized Analysis Lee, Hsiu-Hui
More Stacks Growable stacks Amortized analysis
Splay Trees In balanced tree schemes, explicit rules are followed to ensure balance. In splay trees, there are no such rules. Search, insert, and delete.
CS 583 Analysis of Algorithms
Haim Kaplan, Uri Zwick March 2018
CSCE 411 Design and Analysis of Algorithms
More Stacks Growable stacks Amortized analysis
Lecture 21 Amortized Analysis
CSCE 411 Design and Analysis of Algorithms
Presentation transcript:

Amortized 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.

Three Methods of Amortized Analysis Aggregate analysis: Total cost of n operations/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.

Example 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 n PUSH, 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(n 2 ). Correct, but not tight.

Aggregate Analysis In fact, a sequence of n operations on an initially empty stack cost at most O(n). Why? Each object can be POP only once (including in MULTIPOP) for each time it is PUSHed. #POPs is at most #PUSHs, which is at most n. Thus the average cost of an operation is O(n)/n = O(1). Amortized cost in aggregate analysis is defined to be average cost.

Amortized Analysis: Accounting Method Idea: Assign differing charges to different operations. The amount of the charge is called amortized cost. amortized cost is more or less than actual cost. When amortized cost > actual cost, the difference is saved in specific objects as credits. The credits can be used by later operations whose amortized cost < actual cost. As a comparison, in aggregate analysis, all operations have same amortized costs.

Accounting Method (cont.) Conditions: suppose actual cost is c i for the ith operation in the sequence, and amortized cost is c i ',  i=1 n c i '  i=1 n c i should hold. since we want to show the average cost per operation is small using amortized cost, we need the total amortized cost is an upper bound of total actual cost. holds for all sequences of operations. Total credits is  i=1 n c i ' -  i=1 n c i, which should be nonnegative, Moreover,  i=1 t c i ' -  i=1 t c i ≥0 for any t >0.

Accounting Method: Stack Operations Actual costs: PUSH :1, POP :1, MULTIPOP: min(s,k). Let assign the following amortized costs: PUSH:2, POP: 0, MULTIPOP: 0. Similar to a stack of plates in a cafeteria. Suppose $1 represents a unit cost. When pushing a plate, use one dollar to pay the actual cost of the push and leave one dollar on the plate as credit. Whenever POPing a plate, the one dollar on the plate is used to pay the actual cost of the POP. (same for MULTIPOP). By charging PUSH a little more, do not charge POP or MULTIPOP. The total amortized cost for n PUSH, POP, MULTIPOP is O(n), thus O(1) for average amortized cost for each operation. Conditions hold: total amortized cost ≥total actual cost, and amount of credits never becomes negative.

The Potential Method Same as accounting method: something prepaid is used later. Different from accounting method The prepaid work not as credit, but as “potential energy”, or “potential”. The potential is associated with the data structure as a whole rather than with specific objects within the data structure.

The Potential Method (cont.) Initial data structure D 0, n operations, resulting in D 0, D 1,…, D n with costs c 1, c 2,…, c n. A potential function  : {D i }  R (real numbers)  (D i ) is called the potential of D i. Amortized cost c i ' of the ith operation is: c i ' = c i +  (D i ) -  (D i-1 ). (actual cost + potential change)  i=1 n c i ' =  i=1 n (c i +  (D i ) -  (D i-1 )) =  i=1 n c i +  (D n ) -  (D 0 )

The Potential Method (cont.) If  (D n )   (D 0 ), then total amortized cost is an upper bound of total actual cost. But we do not know how many operations, so  (D i )   (D 0 ) is required for any i. It is convenient to define  (D 0 )=0,and so  (D i )  0, for all i. If the potential change is positive (i.e.,  (D i ) -  (D i- 1 )>0), then c i ' is an overcharge (so store the increase as potential), otherwise, undercharge (discharge the potential to pay the actual cost).

Potential method: stack operation Potential for a stack is the number of objects in the stack. So  (D 0 )=0, and  (D i )  0 Amortized cost of stack operations: PUSH: Potential change:  (D i )-  (D i-1 ) =(s+1)-s =1. Amortized cost: c i ' = c i +  (D i ) -  (D i-1 )=1+1=2. POP: Potential change:  (D i )-  (D i-1 ) =(s-1) –s= -1. Amortized cost: c i ' = c i +  (D i ) -  (D i-1 )=1+(-1)=0. MULTIPOP(S,k): k'=min(s,k) Potential change:  (D i )-  (D i-1 ) = –k'. Amortized cost: c i ' = c i +  (D i ) -  (D i-1 )=k'+(-k')=0. So amortized cost of each operation is O(1), and total amortized cost of n operations is O(n). Since total amortized cost is an upper bound of actual cost, the worse case cost of n operations is O(n).