简体   繁体   English

哈希表冲突处理

[英]Hashtable Collision Handling

I have a hashtable with 11 buckets. 我有一个包含11个存储桶的哈希表。 And have to decide between the hashfunktion 并且必须决定之间的哈希功能

h(k)= k mod 6 or h(k)= k mod 10

Which one is the best solution? 哪一个是最佳解决方案? I think it is h(k)= k mod 10 because with h(k)= k mod 6 there can point 2 or 3 keys to the same bucket. 我认为这是h(k)= k mod 10因为h(k)= k mod 6可以将2个或3个键指向同一存储桶。

And I thought when you have h(k)= k mod 10 the minimum of the buckets have to be 10. 我认为当h(k)= k mod 10时,存储桶的最小值必须为10。

thanks for help. 感谢帮助。

If you must decide between these two functions, mod 10 wins, because it leaves only one bucket unused, as opposed to five buckets that would be unused if you go with mod 6. 如果您必须在这两个功能之间做出选择,则mod 10会获胜,因为它只剩下一个存储桶未使用,而如果您使用mod 6则会有五个存储桶未使用。

Ideally, though, you should use mid 11 for an eleven-bucket hash table, because it spreads hash codes among all available buckets. 不过,理想情况下,您应该对11个存储桶的哈希表使用11点中旬,因为它将哈希码分布在所有可用存储桶中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM