Let U ∈ N + U \in \N^+ U ∈ N + , and S = { x 1 , x 2 , … , x m } ⊆ Z U S = \{ x_1, x_2, \ldots, x_m \} \subseteq \mathbb{Z}_U S = { x 1 , x 2 , … , x m } ⊆ Z U be a set of distinct element.
Consider a function h : Z U → Z n h: \mathbb{Z}_U \rightarrow \mathbb{Z}_n h : Z U → Z n , where n ≤ U n \le U n ≤ U .
We call h h h a hash function.
In the case where n < U n < U n < U , there must be some i ∈ Z n i \in \mathbb{Z}_n i ∈ Z n , s.t., ∣ h − 1 ( i ) ∣ > 1 |h^{-1}(i)| > 1 ∣ h − 1 ( i ) ∣ > 1 .
We are interested in the number of total duplicate value in
h ( S ) ≐ { h ( x 1 ) , h ( x 2 ) , … , h ( x m ) } .
h(S) \doteq \{ h(x_1), h(x_2), \ldots, h(x_m) \}.
h ( S ) ≐ { h ( x 1 ) , h ( x 2 ) , … , h ( x m )} . If both S S S and h h h are fixed, there is nothing uncertain. There are two ways to add some randomness to our analysis
h h h is fixed, and S S S follows some distribution on Z U \mathbb{Z}_U Z U .
E.g., let U = 2 20 U = 2^{20} U = 2 20 and h ( x ) = x & 1023 h(x) = x \ \& \ 1023 h ( x ) = x & 1023 that returns the last 10 10 10 bits of x x x (in binary form).
If S S S is sampled uniformly at random from Z U \mathbb{Z}_U Z U , then on average for each x i ∈ S x_i \in S x i ∈ S , there are k − 1 1024 \frac{k - 1}{1024} 1024 k − 1 elements that have the same value as x i x_i x i under h h h .
The assumption that S S S follows some distribution is too strong.
Instead we assume that given S S S , we select a function h h h uniformly, from a set of functions H \mathcal{H} H .
Now we are interested in the probability
Pr [ h ( x i ) = h ( x j ) ] , i ≠ j .
\Pr[ h(x_i) = h(x_j) ], \quad i \neq j.
Pr [ h ( x i ) = h ( x j )] , i = j .
The finite field F p \mathbb{F}_p F p
Let p > U p > U p > U be a prime number and
H ≐ { h ( x ) ≐ ( a x + b m o d p ) m o d n | a , b ∈ F p } .
\mathcal{H} \doteq \left\{ h(x) \doteq \left( ax + b \mod p \right) \mod n \,
\middle| \, a, b \in \mathbb{F}_p \right\}.
H ≐ { h ( x ) ≐ ( a x + b mod p ) mod n ∣ a , b ∈ F p } .
Theorem. If h h h is sampled uniformly at random from H \mathcal{H} H , then
Pr [ h ( x i ) = h ( x j ) ] ≤ 1 n , x i ≠ x j .
\Pr[ h(x_i) = h(x_j) ] \le \frac{1}{n}, \quad x_i \neq x_j.
Pr [ h ( x i ) = h ( x j )] ≤ n 1 , x i = x j .
Lemma 1. Given x i , x j , s , t ∈ F p x_i, x_j, s, t \in \mathbb{F}_p x i , x j , s , t ∈ F p , s.t., x i ≠ x j x_i \neq x_j x i = x j , there is a unique pair ( a , b ) ∈ F p × F p (a,b) \in \mathbb{F}_p \times \mathbb{F}_p ( a , b ) ∈ F p × F p
a x i + b = s , a x j + b = t ,
a x_i + b = s, \\
a x_j + b = t,
a x i + b = s , a x j + b = t , where the equations hold in the field F p \mathbb{F}_p F p .
Proof. Since x i ≠ x j x_i \neq x_j x i = x j , the following matrix is invertible
[ x i , 1 x j , 1 ] ∈ F p 2 × 2 .
\begin{bmatrix}
x_i , 1 \\
x_j , 1
\end{bmatrix} \in \mathbb{F}_p^{2 \times 2}.
[ x i , 1 x j , 1 ] ∈ F p 2 × 2 . Therefore,
[ a b ] = [ x i , 1 x j , 1 ] − 1 [ s t ]
\begin{bmatrix}
a \\
b
\end{bmatrix}
=
\begin{bmatrix}
x_i, 1 \\
x_j, 1
\end{bmatrix}^{-1}
\begin{bmatrix}
s \\
t
\end{bmatrix}
[ a b ] = [ x i , 1 x j , 1 ] − 1 [ s t ] □ \square □
Proof of the Theorem.
For x i ≠ x j x_i \neq x_j x i = x j ,
Pr [ h ( x i ) = h ( x j ) ] = ∑ s , t ∈ F p , s ≡ t ( m o d n ) Pr [ h ( x i ) = s ∧ h ( x j ) = t ] = ∑ s , t ∈ F p , s ≡ t ( m o d n ) 1 p 2 = ∑ s ∈ F p ( ∑ t ∈ F p , t ≡ s ( m o d n ) 1 p 2 ) ≤ ∑ s ∈ F p p n ⋅ 1 p 2 = 1 n .
\begin{aligned}
\Pr[h(x_i) = h(x_j)]
&= \sum_{s, t \in \mathbb{F}_p, s \equiv t \pmod n} \Pr[ h(x_i) = s \wedge h(x_j) = t] \\
&= \sum_{s, t \in \mathbb{F}_p, s \equiv t \pmod n} \frac{1}{ p^2 } \\
&= \sum_{s \in \mathbb{F}_p} \left( \sum_{t \in \mathbb{F}_p, t \equiv s \pmod n} \frac{1}{ p^2 } \right) \\
&\le \sum_{s \in \mathbb{F}_p} \frac{p}{ n } \cdot \frac{1}{ p^2 } \\
&= \frac{1}{ n }.
\end{aligned}
Pr [ h ( x i ) = h ( x j )] = s , t ∈ F p , s ≡ t ( mod n ) ∑ Pr [ h ( x i ) = s ∧ h ( x j ) = t ] = s , t ∈ F p , s ≡ t ( mod n ) ∑ p 2 1 = s ∈ F p ∑ t ∈ F p , t ≡ s ( mod n ) ∑ p 2 1 ≤ s ∈ F p ∑ n p ⋅ p 2 1 = n 1 . □ \square □
Lemma 3.
The expected number of pair x i , x j x_i, x_j x i , x j , s.t., x i ≠ x j ∧ h ( x i ) = h ( x j ) x_i \neq x_j \wedge h(x_i) = h(x_j) x i = x j ∧ h ( x i ) = h ( x j ) is given by
E [ ∑ x i ≠ x j I h ( x i ) = h ( x j ) ] = ∑ x i ≠ x j Pr [ h ( x i = x j ) ] = ( m 2 ) 1 n = m ( k − 1 ) 2 n
\mathbb{E} \left[
\sum_{x_i \neq x_j} \mathbb{I}_{h(x_i) = h(x_j)}
\right] = \sum_{x_i \neq x_j} \Pr[h(x_i = x_j)] = \binom{m}{2} \frac{1}{n} = \frac{m (k - 1)}{ 2n }
E x i = x j ∑ I h ( x i ) = h ( x j ) = x i = x j ∑ Pr [ h ( x i = x j )] = ( 2 m ) n 1 = 2 n m ( k − 1 )
When m 2 ≤ n m^2 \le n m 2 ≤ n , then E [ ∑ x i ≠ x j I h ( x i ) = h ( x j ) ] ≤ 1 2 \mathbb{E} \left[ \sum_{x_i \neq x_j} \mathbb{I}_{h(x_i) = h(x_j)} \right] \le \frac{1}{2} E [ ∑ x i = x j I h ( x i ) = h ( x j ) ] ≤ 2 1 . By Markov inequality,
Pr [ ∃ collision ] ≤ 1 2 .
\Pr[\exists \, \, \text{collision}] \le \frac{1}{ 2 }.
Pr [ ∃ collision ] ≤ 2 1 .
Lemma 4.
With probability at most 1 / 2 1/2 1/2 , some bin contains more than m n + 2 m \frac{m}{n} + \sqrt{2m} n m + 2 m balls.
For a fixed bin, let Y Y Y denote the number of ball in this bin. Further, define
Y i = { 1 , if the i -th ball falls into the bin 0 , otherwise
Y_i = \begin{cases}
1, \qquad \text{if the } i \text{-th ball falls into the bin} \\
0, \qquad \text{otherwise}
\end{cases}
Y i = { 1 , if the i -th ball falls into the bin 0 , otherwise Then Y = ∑ i Y i Y = \sum_i Y_i Y = ∑ i Y i , and
E [ Y ] = m n
\mathbb{E} [Y] = \frac{m}{n} \\
E [ Y ] = n m By pair-wise independence, we have
V a r [ Y ] = ∑ i V a r [ Y i ] = m 1 n ( 1 − 1 n )
Var[Y] = \sum_i Var[Y_i] = m \frac{1}{n} \left(1 - \frac{1}{n} \right)
V a r [ Y ] = i ∑ V a r [ Y i ] = m n 1 ( 1 − n 1 ) Therefore, by Chebyshev inequality, we have
Pr [ ∣ Y − E [ Y ] ∣ ≥ 2 n m 1 n ( 1 − 1 n ) ] = Pr [ ∣ Y − E [ Y ] ∣ ≥ 2 n ⋅ σ ] ≤ V a r [ Y ] 2 n σ 2 = 1 2 n .
\Pr \left[ |Y - \mathbb{E}[Y]| \ge \sqrt{2n} \sqrt{ m \frac{1}{n} \left(1 - \frac{1}{n} \right)} \right]
= \Pr[|Y - \mathbb{E}[Y]| \ge \sqrt{2n} \cdot \sigma] \le \frac{Var[Y]}{2n\sigma^2} = \frac{1}{2n}.
Pr [ ∣ Y − E [ Y ] ∣ ≥ 2 n m n 1 ( 1 − n 1 ) ] = Pr [ ∣ Y − E [ Y ] ∣ ≥ 2 n ⋅ σ ] ≤ 2 n σ 2 V a r [ Y ] = 2 n 1 . Finally, applying union bound over n n n bins, we get
Pr [ some bin gets more than 2 m balls ] ≤ 1 2 .
\Pr[\text{some bin gets more than } \sqrt{2m} \text{ balls} ] \le \frac{1}{2}.
Pr [ some bin gets more than 2 m balls ] ≤ 2 1 . The finite field F 2 k \mathbb{F}_{2^k} F 2 k
We consider an extension such that each element x i ∈ S x_i \in S x i ∈ S is now a vector ∈ F 2 k \in \mathbb{F}_2^k ∈ F 2 k .
We would like to have some operations ⊗ \otimes ⊗ and ⊕ \oplus ⊕ , such that if we sample a hash function h : F 2 k → F 2 k h : \mathbb{F}_2^k \rightarrow \mathbb{F}_2^k h : F 2 k → F 2 k uniformly at random from the following family
H = { h ( x ) ≐ a ⊗ x ⊕ b | a , b ∈ F 2 k } ,
\mathcal{H} = \left\{ h(x) \doteq a \otimes x \oplus b \,
\middle| \, a, b \in \mathbb{F}_2^k \right\},
H = { h ( x ) ≐ a ⊗ x ⊕ b a , b ∈ F 2 k } , then h ( x i ) h(x_i) h ( x i ) and h ( x j ) h(x_j) h ( x j ) are pairwise independent for x i ≠ x j x_i \neq x_j x i = x j .
In particular, when x i ≠ x j x_i \neq x_j x i = x j , it holds that
Pr [ h ( x i ) = s ∧ h ( x j ) = t ] = Pr [ h ( x i ) = s ] ⋅ Pr [ h ( x j ) = t ] = ( 1 2 k ) 2 , ∀ s , t ∈ F 2 k .
\begin{align*}
\Pr[ h(x_i) = s \, \wedge \, h(x_j) = t]
&= \Pr[ h(x_i) = s ] \cdot \Pr[ h(x_j) = t ] \\
&= \left( \frac{1}{2^k} \right)^2,
&\quad \forall s, t \in \mathbb{F}_2^k.
\end{align*}
Pr [ h ( x i ) = s ∧ h ( x j ) = t ] = Pr [ h ( x i ) = s ] ⋅ Pr [ h ( x j ) = t ] = ( 2 k 1 ) 2 , ∀ s , t ∈ F 2 k . We would like the a , b ∈ F 2 k a, b \in \mathbb{F}_2^k a , b ∈ F 2 k to be determined by
[ a b ] = [ x i , 1 x j , 1 ] − 1 [ s t ] .
\begin{bmatrix}
a \\
b
\end{bmatrix}
=
\begin{bmatrix}
x_i, 1 \\
x_j, 1
\end{bmatrix}^{-1}
\begin{bmatrix}
s \\
t
\end{bmatrix}.
[ a b ] = [ x i , 1 x j , 1 ] − 1 [ s t ] . In order that this holds, the set of vectors F 2 m \mathbb{F}_2^m F 2 m , when augmented with operations ⊗ \otimes ⊗ and ⊕ \oplus ⊕ , should constitute a field .
Fact. For each k ∈ N + k \in \mathbb{N}^+ k ∈ N + , there is a polynomial q k q_k q k with coefficients in F 2 \mathbb{F}_2 F 2 and of degree k k k that is irreducible (cannot be factor).
We now view x i = ( x i [ 0 ] , … , x i [ k − 1 ] ) x_i = (x_i[0], \ldots, x_i[k - 1]) x i = ( x i [ 0 ] , … , x i [ k − 1 ]) as a polynomial
p x i ( z ) ≐ ( x i [ 0 ] + x i [ 1 ] ⋅ z + ⋯ + x i [ k − 1 ] ⋅ z k − 1 ) m o d q k .
p_{x_i}(z) \doteq \left( x_i[0] + x_i[1] \cdot z + \cdots + x_i[k - 1] \cdot z^{k - 1} \right) \mod q_k.
p x i ( z ) ≐ ( x i [ 0 ] + x i [ 1 ] ⋅ z + ⋯ + x i [ k − 1 ] ⋅ z k − 1 ) mod q k . The ⊕ \oplus ⊕ is defined to be the addition of polynomials.
Hence,
x i ⊕ x j = ( x i [ 0 ] + x j [ 0 ] , … , x i [ k − 1 ] + x j [ k − 1 ] ) ,
x_i \oplus x_j
= (x_i[0] + x_j[0], \ldots, x_i[k - 1] + x_j[k - 1]),
x i ⊕ x j = ( x i [ 0 ] + x j [ 0 ] , … , x i [ k − 1 ] + x j [ k − 1 ]) , since
p x i ( z ) + p x j ( z ) = ( ( x i [ 0 ] + x j [ 0 ] ) + ( x i [ 1 ] + x j [ 1 ] ) ⋅ z + ⋯ + ( x i [ k − 1 ] + x j [ k − 1 ] ) ⋅ z k − 1 ) m o d q k .
\begin{aligned}
&p_{x_i}(z) + p_{x_j}(z) \\
&= \left( ( x_i[0] + x_j[0] ) + ( x_i[1] + x_j[1] ) \cdot z + \cdots + ( x_i[k - 1] + x_j[k - 1] ) \cdot z^{k - 1} \right) \mod q_k.
\end{aligned}
p x i ( z ) + p x j ( z ) = ( ( x i [ 0 ] + x j [ 0 ]) + ( x i [ 1 ] + x j [ 1 ]) ⋅ z + ⋯ + ( x i [ k − 1 ] + x j [ k − 1 ]) ⋅ z k − 1 ) mod q k . Moreover, we can consider the ⊗ \otimes ⊗ as polynomial multiplications ( m o d q ) k \pmod q_k ( mod q ) k , which results in a polynomial of degree at most k k k .
Finally, since q k q_k q k is irreducible, if x i ≠ 0 x_i \neq 0 x i = 0 , there exists polynomial c c c and d d d , such that c ( m o d q ) k ≡ c c \pmod q_k \equiv c c ( mod q ) k ≡ c and
1 = c ⋅ x i + d ⋅ q k .
1 = c \cdot x_i + d \cdot q_k.
1 = c ⋅ x i + d ⋅ q k . Hence, c c c can be viewed as the inverse of x i x_i x i and division is well-defined.
It concludes that ( F 2 k , ⊗ , ⊕ ) (\mathbb{F}_2^k, \otimes, \oplus) ( F 2 k , ⊗ , ⊕ ) constitute a field.
Reference
[1] Sanjeev Arora, Cos 521: Advanced Algorithm Design, Lecture 1: Course Intro and Hashing.
[2] Nick Harvey, CPSC 536N: Randomized Algorithms 2014-15 Term 2, Lecture 13, University of British Columbia
← Back to all notes Back to top ↑