Suppose that you are planning to store a set of k-bit integers using a hash table of size n. Let N = 2^k. (There is nothing special about this choice.) Hash Function: Fix a prime number p that is at least N. (From number theory, we know that there is at least one prime number between N and 2N.) Choose your hash function at random using the following procedure:
- Choose an integer a such that 1 <= a <= p - 1 uniformly at random. Then, independent from the first choice, choose an integer b such that 0 <= b <= p - 1 uniformly at random.
- The hash function is then
h(x) = ((a * x + b) mod p) mod n
Show that for any two distinct k bit integers x != y
P(h(x) = h(y)) <= (2) / (n)
Note that the probability here is over the random choice of a and b. You may use without proof the facts:
1. From CSE 311: If gcd(z, p) = 1, for each c there is a unique solution a modulo p of a * z = c (mod p)
2. For any two numbers s, t in {0, 1, 2, ..., p - 1}, and any x != y in {0, 1, 2, ..., p - 1}, there is a unique pair 0 <= a <= p - 1 and 0 <= b <= p - 1 such that
s = (a * x + b) mod p, and t = (a * y + b) mod p
which follows by applying the first fact to z = x - y.