{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

07-Hashing-I

07-Hashing-I - Algorithms LECTURE 7 Hashing I Direct-access...

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

Algorithms L7.1 Professor Ashok Subramanian L ECTURE 7 Hashing I Direct-access tables Resolving collisions by chaining Choosing hash functions Open addressing Algorithms

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

View Full Document
Algorithms L7.2 Symbol-table problem Symbol table S holding n records : key [ x ] record x Other fields containing satellite data Operations on S : I NSERT ( S , x ) D ELETE ( S , x ) S EARCH ( S , k ) How should the data structure S be organized?
Algorithms L7.3 Direct-access table I DEA : Suppose that the keys are drawn from the set U {0, 1, …, m –1} , and keys are distinct. Set up an array T [0 . . m –1] : T [ k ] = x if x 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
Algorithms L7.4 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 S k k k k k 0 m –1 h ( k ) h ( k ) h ( k ) h ( k ) When a record to be inserted maps to an already occupied slot in T , a collision occurs. T = h ( k )
Algorithms L7.5 Resolving collisions by chaining Link records in the same slot into a list. h (49) = h (86) = h (52) = i T i 49 86 52 Worst case: Every key hashes to the same slot. Access time = Θ ( n ) if | S | = n

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

View Full Document
Algorithms L7.6 Average-case analysis of chaining We make the assumption of simple uniform hashing: Each key k S 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.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}