Why is $h(x) = (x^2 + 1) \mod 11$ a bad choice for a hash function considering an array of 11 slots?

235 Views Asked by At

Why is $h(x) = (x^2 + 1) \mod 11$ a bad choice for a hash function considering an array of 11 slots?

We consider uniform hashing so we have two conditions to respect:

  1. Uniformity: meaning that we have $h(k) = i $ with probability $1/M$ for all $i = 0,1,...,M-1$
  2. Independance: For multiple keys $(k_1,k_2,...,k_m)$ the hashing values $(h(k_1),h(k_2),...,h(k_m))$ follows a uniform distribution.

I fail to see how the above hash function is a bad choice.

1

There are 1 best solutions below

0
On

It's easy to see that at least half of the values are not used because $(-x)^2=x^2$, causing $\{0,\dots,5\}$ to reflect $\{11,...,6\}$.

Indeed, just write out all the values out yourself and you will see many are missing. See here for coded example.