Why is choosing a prime number common practice for the size of a hash table?

• 本文约59字,阅读大致需要1分钟Development

It’s a common practice to choose a prime number as the hash table size. This article analyzes Java’s implementation.

To make it short, it is important to avoid collisions in a hash table in order to maximize its O(1)O(1) search benefits. A funnel will occur only if the keys are multiples of the prime number; this will help prevent collisions.

搜索文章…(按ESC退出)