lecture07

# lecture07 - Introduction to Algorithms...

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

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

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

View Full Document
Introduction to Algorithms Day 11 L7.2 © 2001 by Charles E. Leiserson Symbol-table problem Symbol table T holding n records : key [ x ] key [ x ] record x Other fields containing satellite data Operations on T : I NSERT ( T , x ) D ELETE ( T , x ) S EARCH ( T , k ) How should the data structure T be organized?
Introduction to Algorithms Day 11 L7.3 © 2001 by Charles E. Leiserson Direct-access table I DEA : Suppose that the set of keys is K {0, 1, …, m –1} , and keys are distinct. Set up an array T [0 . . m –1] : T [ k ] = x if k K and key [ x ] = k , NIL otherwise. Then, operations take Θ (1) time. Problem: The range of keys can be large: 64 -bit numbers (which represent 18,446,744,073,709,551,616 different keys), character strings (even larger!).

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

View Full Document
Introduction to Algorithms Day 11 L7.4 © 2001 by Charles E. Leiserson As each key is inserted, h maps it to a slot of T . Hash functions Solution: Use a hash function h to map the universe U of all keys into {0, 1, …, m –1} : U K k 1 k 2 k 3 k 4 k 5 0 m –1 h ( k 1 ) h ( k 4 ) h ( k 2 ) h ( k 3 ) When a record to be inserted maps to an already occupied slot in T , a collision occurs. T = h ( k 5 )
Introduction to Algorithms Day 11 L7.5 © 2001 by Charles E. Leiserson Resolving collisions by chaining Records in the same slot are linked into a list. h (49) = h (86) = h (52) = i T 49 49 86 86 52 52 i

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

View Full Document
Introduction to Algorithms Day 11 L7.6 © 2001 by Charles E. Leiserson Analysis of chaining We make the assumption of simple uniform hashing: Each key k K of keys is equally likely to be hashed to any slot of table T , independent of where other keys are hashed. Let n be the number of keys in the table, and let m be the number of slots. Define the load factor of T to be α = n / m = average number of keys per slot.
Day 11 L7.7 © 2001 by Charles E. Leiserson Search cost Expected time to search for a record with a given key = Θ (1 + α ) . apply hash

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 07/09/2009 for the course CSE 6.046J/18. taught by Professor Piotrindykandcharlese.leiserson during the Fall '04 term at MIT.

### Page1 / 24

lecture07 - Introduction to Algorithms...

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

View Full Document
Ask a homework question - tutors are online