Question

How does a constant before the key in the formula:

h(k) = (const * key) % m,

affect the distribution of the hash values in the table?

Are there any rules on how to choose such a constant to minimize collisions and get an even distribution of the keys in the hash table?

Was it helpful?

Solution

The constant factor should be prime, and if I remember correctly it should be relatively prime w.r.t. the modulus. This is all discussed at great length in Knuth Volume III.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top