Presentation by Marty Krogel

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.
1 Chapter 17: Amortized Analysis III. 2 Dynamic Table Sometimes, we may not know in advance the #objects to be stored in a table We may allocate space.
CS261 Data Structures Dynamic Arrays. Pro: only core data structure designed to hold a collection of elements Pro: random access: can quickly get to any.
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.
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.
Theory I Algorithm Design and Analysis (8 – Dynamic tables) Prof. Th. Ottmann.
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]
Tirgul 11 Solutions for questions from T2, T3 DFS & BFS - reminder Some Hashing Reminder : don’t forget to run ~dast/bin/testEx3.csh on your jar file before.
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.
Amortized Analysis Not just consider one operation, but a sequence of operations on a given data structure. Average cost over a sequence of operations.
CS 473Lecture 121 CS473-Algorithms I Lecture 12 Amortized Analysis.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 14 Prof. Charles E. Leiserson.
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 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.
Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner.
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.
© 2004 Goodrich, Tamassia Vectors1 Vectors and Array Lists.
Array Lists1 © 2010 Goodrich, Tamassia. Array Lists2 The Array List ADT  The Array List ADT extends the notion of array by storing a sequence of arbitrary.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
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.
Introduction to Algorithms Amortized Analysis My T. UF.
David Luebke 1 2/26/2016 CS 332: Algorithms Dynamic Programming.
Amortized Analysis In amortized analysis, the time required to perform a sequence of operations is averaged over all the operations performed Aggregate.
Amortized Analysis and Heaps Intro David Kauchak cs302 Spring 2013.
Introduction to Algorithms: Amortized Analysis. Introduction to Algorithms Amortized Analysis Dynamic tables Aggregate method Accounting method Potential.
Amortized Analysis.
Lists and Iterators 5/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Amortized Analysis of Rehashing
Andreas Klappenecker [partially based on the slides of Prof. Welch]
Data Structures Using C++ 2E
Hash table CSC317 We have elements with key and satellite data
Complexity analysis.
Linked Lists Linked Lists 1 Sequences Sequences 07/25/16 10:31
Amortized Analysis (chap. 17)
CSCE 411 Design and Analysis of Algorithms
Table Amortized cost: $3 Insert 5 Actual cost: $1.
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
Lecture 16 Amortized Analysis
Data Structures Using C++ 2E
Lists and Iterators 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Vectors 11/23/2018 1:03 PM Growing Arrays Vectors.
" A list is only as strong as its weakest link. " - Donald Knuth
Array-Based Sequences
Priority Queues (Chapter 6.6):
CSCE 411 Design and Analysis of Algorithms
CS 332: Algorithms Amortized Analysis Continued
Amortized Analysis and Heaps Intro
Priority Queues (Chapter 6):
Vectors and Array Lists
Lecture 21 Amortized Analysis
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
CSCE 411 Design and Analysis of Algorithms
Presentation transcript:

Presentation by Marty Krogel Chapter 17 Amortized Analysis Presentation by Marty Krogel

Definition Amortized analysis - A way of analyzing the time required to perform a series of operations on a data-structure by averaging the cost over all operations performed.

Chapter Outline 17.1 Aggregate analysis 17.2 The accounting method 17.3 The potential method 17.4 Dynamic tables (Applying the potential method) 17.4.1 Table expansion 17.4.2 Table expansion and contraction

17.1 Aggregate analysis The aggregate analysis spreads the total cost evenly amongst all operations performed. (Later analysis methods assign different costs to different operations.) If the worst-case time of a series of operations is T(n), then the average cost, or amortized cost per operation is T(n)/n.

Stack example (On the whiteboard)

Incrementing binary counter example

Increment binary counter INCREMENT(A) i  0 while i < length[A] and A[i] = 1 do A[i]  0 i  i + 1 if i < length[A] then A[i]  1

Binary counter

Cost of INCREMENT

17.2 The accounting method For the accounting method, different operations are assigned different costs, called their amortized cost. When an operation’s amortized cost is greater than it’s actual cost, the difference is assigned as credit to specific objects in a data structure and can be used later by operations who’s amortized cost is less than it’s actual cost.

Amortized cost notation The sum of amortized cost of the n operations is greater than or equal to the sum of the actual cost of the n operations.

Stack example (On the whiteboard)

Incrementing binary counter example (On the whiteboard)

17.3 The potential method Instead of representing the prepaid work as credit, the potential method treats it as “potential energy” or just “potential” which is stored until it is needed later to pay for other operations. Where Di represents the data structure after the ith operation, the potential function F maps the data structure Di to a real number F (Di). Thus, we are able to come up with an equation for the amortized cost of the ith operation.

Potential amortized cost

Stack example (On the whiteboard)

Incrementing binary counter example (On the whiteboard)

17.4 Dynamic tables As we all know, expanding an array involves creating a new array of a larger size and copying over all the elements in it, therefore it takes O(n) time. What if I told you that, using amortized analysis, we can prove that a series of insertion operations on an array has a constant amortized cost, despite requiring a number of array expansions?

Table expansion TABLE-INSERT(T, x) if size[T] = 0 then allocate table[T] with 1 slot size[T]  1 if num[T] = size[T] then allocate new-table with 2 x size[T] slots insert all items in table[T] into new-table free table[T] table[T]  new-table size[T]  2 x size[T] insert x into table[T] num[T]  num[T] + 1

Table expansion

Table expansion and contraction Since we double the table size when it is full, never dropping below a load factor of ½, one might think to contract the table when the load factor becomes ½. (This doesn’t work.) Consider the case when n operations are performed on a table, where the first n/2 operations are insert (filling up the table). Then the following series is used for the next n/2 operations: Ins,Del,Del,Ins,Ins,Del,Del,Ins,Ins… This would result in n/2 expansions and contractions, each costing Q(n), for a total cost of Q(n2), which leaves us with an amortized cost of Q(n) per operation.

Potential method analysis Solution: Don’t contract the table until the load factor gets below ¼, then reduce the table size by ½. a(T) is the load factor and is equal to num[T] / size[T].

Case 1: TABLE-INSERT when ai-1 ³ ½. ĉi = 3. (Calculated previously) Case 2: TABLE-INSERT when ai-1 < ½. ĉi = ci + Fi – Fi-1 = 1 + (sizei/2 – numi) – (sizei-1/2 – numi-1) = 1 + (sizei/2 – numi) – (sizei/2 – numi –1) = 0. Case 3: TABLE-INSERT when ai-1 < ½, but ai ³ ½. = 1 + (2 · numi –sizei) – (sizei-1/2 – numi-1) = 1 + (2(numi-1+1) – sizei-1) – (sizei-1/2 – numi-1) = 3 · numi-1 – (3/2) sizei-1+ 3 = 3ai-1sizei-1 – (3/2)sizei-1+ 3 = (3/2)sizei-1 – (3/2)sizei-1 + 3 = 3.

Case 4: TABLE-DELETE when ai-1 < ½ but no contraction. ĉi = ci + Fi – Fi-1 = 1 + (sizei /2 – numi) – (sizei-1/2 – numi-1) = 1 + (sizei /2 – numi) – (sizei /2 – (numi +1)) = 2. Case 5: TABLE-DELETE when ai-1 < ½ with contraction. = (numi + 1) + (sizei /2 – numi) – (sizei-1/2 – numi-1) = (numi + 1) + ((numi + 1) – numi) – ((2 · numi + 2) – (numi + 1)) = 1. Case 6: TABLE-DELETE when ai-1 ³ ½, but ai < ½. = 1 + (sizei /2 – numi) – (2 · numi-1 – sizei-1) = 1 + (3/2)sizei – (numi-1 – 1) – 2(numi-1 ) = (3/2)sizei – 3 numi = (3/2)sizei – (3/2)sizei = 0. Case 7: TABLE-DELETE when ai, ai-1 ³ ½. = 1 + (2 · numi – sizei) – (2 · numi-1 – sizei-1) = 1 + 2(numi – (numi+1)) + (sizei – sizei) = 1 – 2 + 0 = – 1