문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top