Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top