Contents
Page-10
Prev
Next
Page+10
Index
Collisions
Even if the hash function is randomizing, it is inevitable that
sometimes different keys will hash to the same value; this is called
a collision.
The load factor λ is the ratio
of hash table entries to table size. Obviously, the higher
λ is, the greater the probability of a collision.
There are two basic ways to handle a collision:
- Rehash the key using a different hash function.
The simplest method of rehashing is linear probing,
simply adding 1 to the previous hash
value (modulo table size). Other options are quadratic probing
and double hashing, using a different hash function. With rehashing,
access to the hash table is efficient if the λ is kept below 0.7;
this wastes nearly half of the storage.
- Let each table entry point to a bucket of entries,
an auxiliary data structure such as a linked list.