07-Hashing-I

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

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

View Full Document Right Arrow Icon
Algorithms L7.1 Professor Ashok Subramanian L ECTURE 7 Hashing I Direct-access tables Resolving collisions by chaining Choosing hash functions Open addressing Algorithms
Background image of page 1

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

View Full DocumentRight Arrow Icon
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?
Background image of page 2
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!).
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 )
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/29/2011 for the course IT 201 taught by Professor K.v.arya during the Spring '11 term at IIT Kanpur.

Page1 / 26

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online