# lec13 - Introduction to Algorithms 6.046J/18.401J LECTURE...

This preview shows pages 1–15. Sign up to view the full content.

October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.1 Introduction to Algorithms 6.046J/18.401J L ECTURE 13 Amortized Analysis Dynamic tables Aggregate method Accounting method Potential method Prof. Charles E. Leiserson

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.2 How large should a hash table be? Goal: Make the table as small as possible, but large enough so that it won’t overflow (or otherwise become inefficient). Problem: What if we don’t know the proper size in advance? I DEA : Whenever the table overflows, “grow” it by allocating (via malloc or new ) a new, larger table. Move all items from the old table into the new one, and free the storage for the old table. Solution: Dynamic tables.
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.3 Example of a dynamic table 1. I NSERT 1 2. I NSERT overflow

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.4 Example of a dynamic table 1. I NSERT 1 1 2. I NSERT overflow
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.5 Example of a dynamic table 1. I NSERT 1 1 2. I NSERT 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.6 Example of a dynamic table 1. I NSERT 1 1 2. I NSERT 2 2 3. I NSERT overflow
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.7 Example of a dynamic table 1. I NSERT 2 1 2. I NSERT 3. I NSERT overflow

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.8 Example of a dynamic table 1. I NSERT 1 2. I NSERT 2 3. I NSERT
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.9 Example of a dynamic table 1. I NSERT 2. I NSERT 3. I NSERT 4. I NSERT 4 3 2 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.10 Example of a dynamic table 1. I NSERT 1 2. I NSERT 2 3 3. I NSERT 4. I NSERT 5. I NSERT 4 overflow
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.11 Example of a dynamic table 1. I NSERT 2. I NSERT 4 3 2 1 3. I NSERT 4. I NSERT 5. I NSERT overflow

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.12 Example of a dynamic table 1. I NSERT 2. I NSERT 1 2 3 3. I NSERT 4. I NSERT 5. I NSERT 4
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.13 Example of a dynamic table 1. I NSERT 2. I NSERT 3. I NSERT 4. I NSERT 6. I NSERT 6 5. I NSERT 5 4 3 2 1 7 7. I NSERT

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 31, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L13.14 Worst-case analysis Consider a sequence of n insertions. The worst-case time to execute one insertion is Θ ( n ) . Therefore, the worst-case time for n insertions is n · Θ ( n ) = Θ ( n 2 ) . WRONG! In fact, the worst-case cost for n insertions is only Θ ( n ) Θ ( n 2 ) .
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/19/2010 for the course CS 477 taught by Professor Gewali during the Spring '08 term at University of Nevada, Las Vegas.

### Page1 / 42

lec13 - Introduction to Algorithms 6.046J/18.401J LECTURE...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online