Tuesday, August 24, 2010

Universal hash with mod p

A universal hash is a class of hash functions H with finite number of hashing functions. Moreover, for any given 0 <= i < j <= m-1,the number of hash functions in H which cause h(i)=h(j) is no more than |H| / m. That is to say, for a randomly chosen hash function from H, the probability Pr{h(i)=h(j)} <= 1/m.
For a sufficiently large prime p and for any 1 < m < p, the hash functions h(k) = ak+b mod p is a universal hash. |H| = p(p-1).
for any given i < j, s = ai+b mod p, l = aj+b mod p, if l = s mod p, then a(i-j) = 0 mod p, this is impossible.
(s, l) is a function of (a, b) if (i, j) is given.
As (s-l) = a(i-j) mod p, there exists and only exists one a. Therefore, (a, b) is a function of (s, l) if (i, j) is given.
So the hash function is a one-one map between (a, b) and (s, l) if (i, j) is give. |{s, l}| = |{a, b}| = p(p-1).
So |h(i)=h(j) mod m| <= p(ceiling(p/m)-1) <= p(p-1)/m = |H| / m.
A large prime is useful!


No comments:

Post a Comment