Supposing simple uniform hashing, that being, any given value is equally like to hash into any of the slots of the hash. Why is it better to use a table of size 127 and not 128? I really don't understand what's the problem with the power of 2 numbers. Or how it actually makes any difference at all.
When using the division method, we usually avoid certain values of m (table size). For example, m should not be a power of 2, since if m = 2^p , then h(k) is just the p lowest-order bits of k.
Let's suppose the possible elements are only between 1 and 10000 and I picked the table size as 128. How can 127 be better? So 128 is 2^6 (1000000) and 127 is 0111111. What difference does this make? All numbers (when hashed) are still going to be the p lowest-order bits of k for 127 too. Did I get something wrong?
I'm looking for some examples as I really can't understand why is this bad. Thanks a lot in advance!
PS: I am aware of: Hash table: why size should be prime?
> PS: I am aware of: Hash table: why size should be prime?
- then read it again, or link through to this onen!
). But that is not the generic science behind hashing.Clash
is a very nice screen name to use when talking about hash collisions :)