Introduction to Algorithms, Second Edition

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

View Full Document Right Arrow Icon
The University of Texas at Austin Hashing Department of Computer Sciences Professor Vijaya Ramachandran Lecture 20 CS357: ALGORITHMS, Spring 2006 1 Hashing Hashing is a widely-used class of data structures that support the operations of insert, delete and search on a dynamic set of keys S . The keys are drawn from a universe U ( | U | >> | S | ), which for our purposes will be a set of positive integers. These keys are mapped into a hash table using a hash function ; the size of the hash table is usually within a constant factor of the number of elements in the current set S . There are two main methods used to implement hashing: hashing with chain- ing and hashing with open addressing . We will study hashing with chaining here. 1.1 Hashing with Chaining In hashing with chaining , the elements in S are stored in a hash table T [0 .. m 1] of size m , where m is somewhat larger than n , the size of S . The hash table is said to have m slots . Associated with the hashing scheme is a hash function h which is a mapping from U to { 0 , ··· , m 1 } . Each key k S is stored in location T [ h ( k )], and we say that key k is hashed into slot h ( k ). If more than one key in S hashes into the same slot, then we have a collision . In such a case, all keys that hash into the same slot are placed in a linked list associated with that slot; this linked list is called the chain at that slot. The load factor of a hash table is deFned to be α = n/m ; it represents the average number of keys per slot. We typically operate in the range m = Θ( n ) so α is usually a constant (usually α < 1). If a large number of insertions or deletions destroys this property, a more suitable value of m is chosen and the keys are re-hashed into a new table with a new hash function.
Background image of page 1

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

View Full DocumentRight Arrow Icon
In simple uniform hashing we assume that we have a ‘good’ hash function h such that any element in U is equally likely to hash into any of the m slots in T , independent of the other keys in the table. We also assume that h ( k ) can be computed in constant time. In hashing with chaining, inserts and deletes can be performed in constant time with a suitable linked list representation for the chains. In the worst case, a search operation can take as long as n steps if all keys hash into the same slot. However, if we assume simple uniform hashing then the expected
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

Lecture 20 - The University of Texas at Austin Department...

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

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