- By "size" of the hash table we mean how many slots or buckets it has
- Choice of hash table size depends in part on choice of hash function, and collision resolution strategy
- But a good general “rule of thumb” is:
- The hash table should be an array with length about 1.3 times the maximum number of keys that will actually be in the table, and
- Size of hash table array should be a prime number
- So, let M = the next prime larger than 1.3 times the number of keys you will want to store in the table, and create the table as an array of length M
- (If you underestimate the number of keys, you may have to create a larger table and rehash the entries when it gets too full; if you overestimate the number of keys, you will be wasting some space)
FAQs
What is a good size for a hash table? ›
But a good general “rule of thumb” is: The hash table should be an array with length about 1.3 times the maximum number of keys that will actually be in the table, and. Size of hash table array should be a prime number.
When should you resize a hash table? ›> When the hash table gets too full, we need to allocate a larger array and move the items over. This is absolutely required when the number of items in the hash table has reached the size of the array, but usually you want to do it when the table is half or three-quarters full.
What is perfect hash size? ›Minimal perfect hash function
In practice, there are minimal perfect hashing schemes that use roughly 1.56 bits/key if given enough time.
We have three primary requirements in implementing a good hash function for a given data type: It should be deterministic—equal keys must produce the same hash value. It should be efficient to compute. It should uniformly distribute the keys.