{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture14

# lecture14 - Introduction to Algorithms...

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

Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 14 Prof. Charles E. Leiserson

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

View Full Document
Introduction to Algorithms Day 24 L14.2 © 2001 by Charles E. Leiserson How large should a hash table be? Problem: What if we don’t know the proper size in advance? Goal: Make the table as small as possible, but large enough so that it won’t overflow (or otherwise become inefficient). 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.
Introduction to Algorithms Day 24 L14.3 © 2001 by Charles E. Leiserson 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
Introduction to Algorithms Day 24 L14.4 © 2001 by Charles E. Leiserson 1 Example of a dynamic table 1. I NSERT 2. I NSERT overflow
Introduction to Algorithms Day 24 L14.5 © 2001 by Charles E. Leiserson 1 2 Example of a dynamic table 1. I NSERT 2. I NSERT

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

View Full Document
Introduction to Algorithms Day 24 L14.6 © 2001 by Charles E. Leiserson Example of a dynamic table 1. I NSERT 2. I NSERT 1 2 3. I NSERT overflow
Introduction to Algorithms Day 24 L14.7 © 2001 by Charles E. Leiserson Example of a dynamic table 1. I NSERT 2. I NSERT 3. I NSERT 2 1 overflow

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

View Full Document
Introduction to Algorithms Day 24 L14.8 © 2001 by Charles E. Leiserson Example of a dynamic table 1. I NSERT 2. I NSERT 3. I NSERT 2 1
Introduction to Algorithms Day 24 L14.9 © 2001 by Charles E. Leiserson 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
Introduction to Algorithms Day 24 L14.10 © 2001 by Charles E. Leiserson Example of a dynamic table 1. I NSERT 2. I NSERT 3. I NSERT 4. I NSERT 5. I NSERT 4 3 2 1 overflow
Introduction to Algorithms Day 24 L14.11 © 2001 by Charles E. Leiserson Example of a dynamic table 1. I NSERT 2. I NSERT 3. I NSERT 4. I NSERT 5. I NSERT 4 3 2 1 overflow

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

View Full Document
Introduction to Algorithms Day 24 L14.12 © 2001 by Charles E. Leiserson Example of a dynamic table 1. I NSERT 2. I NSERT 3. I NSERT 4. I NSERT 5. I NSERT 4 3 2 1
Introduction to Algorithms Day 24 L14.13 © 2001 by Charles E. Leiserson 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
Introduction to Algorithms Day 24 L14.14 © 2001 by Charles E. Leiserson 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.

{[ snackBarMessage ]}

### Page1 / 34

lecture14 - Introduction to Algorithms...

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

View Full Document
Ask a homework question - tutors are online