Hash functions for integers: random functions
-
A hash function tries to distribute keys "randomly" over table locations
-
For typical integer keys K, with prime table size M, hash function K mod M usually does a good job of this
-
But with any hash function, it is possible to have "bad" behavior, where most all keys the user happens to want to insert in the hash table hash to the same location
-
To make this very unlikely to happen twice in a row, the hash function can be a pseudorandom number generator whose output depends on a "random" seed decided when the table is created, and on the key value
-
this is called "random hashing", which we will discuss in a moment
-
Random hashing is mostly of theoretical interest; it is not used much in practice because other, simpler hash functions give results that are as good
CONTENTS PREVIOUS NEXT