0% found this document useful (0 votes)
8 views2 pages

PR 9

Uploaded by

rohakdebnath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

PR 9

Uploaded by

rohakdebnath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ESO207A: Data Structures and Algorithms

Practice Set 9: Hash Functions –

Problem 1. Let [m] denote the set {0, 1, 2 . . . , m − 1}. For each of the following families of hash
functions, say whether or not it is universal, and determine how many random bits are needed to
choose a function from the family.

1. H = {ha1 ,a2 | a1 , a2 ∈ [m]}, where m is a fixed prime and

ha1 ,a2 (x1 , x2 ) = a1 x1 + a2 x2 mod m .

Here x1 , x2 ∈ {0, . . . m − 1}.

2. H is the same as before except that m = 2k , for some fixed positive integer k.

3. H is the set of all functions f : [m] → [m − 1].

1
Solution. (1) is universal. The proof is very similar to what has been done in the class (where we
used a four tuple). To repeat the argument, we have to calculate the probability that h(x1 , x2 ) =
h(y1 , y2 ), given that (x1 , x2 ) 6= (y1 , y2 ). Assume that x2 6= y2 . Then, the above equation is

a1 x1 + a2 x2 = a1 y1 + a2 y2 mod m

or, that
a1 (x1 − y1 ) = a2 (y2 − y1 ) mod m .
Since, m is prime, and y2 6= y1 , y2 − y1 has an inverse modulo m, which fixes a2 in the above
1
equation (modulo m). Thus, Pr(h(x1 , x2 ) = h(y1 , y2 )) = m , since, a1 can take any value, but that
fixes exactly 1 out of m values of a2 . Hence, the probability (if a1 , a2 are chosen randomly) that
1
h(x1 , x2 ) = h(y1 , y2 ) is m .
(2) Now suppose m = 2k . Then, y2 − y1 if non-zero need not have an inverse, if it is even (for
example). So H is not universal.
(3) H is the set of all functions from [m] to [m − 1]. So, for x 6= y, h(x) = h(y) has how many
solutions? Since, h(x) = h(y), x, y together get mapped to the same value in m − 1 ways. Every
other value z ∈ [m] \ {x, y} gets mapped in m − 1 ways. Total is (m − 1)m−2+1 = (m − 1)m−1 . The
possible number of hash functions, that is, the size |H| = (m − 1)m . Hence, the probability is

Number of hash functions s.t. h(x) = h(y) (m − 1)m−1 1


Pr(h(x) = h(y)) = = =
Total number of hash functions (m − 1)m m−1

and hence is universal.

You might also like