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 &lambda is the ratio
of hash table entries to table size. Obviously, the higher
&lambda 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,
the &lambda should be kept well below 1; this wastes some storage.
- Let each table entry point to a bucket of entries,
an auxiliary data structure such as a linked list.
Contents
Page-10
Prev
Next
Page+10
Index