高级算法 (Fall 2021)/Limited independence
-wise independence
Recall the definition of independence between events:
Definition (Independent events) - Events
are mutually independent if, for any subset ,
- Events
Similarly, we can define independence between random variables:
Definition (Independent variables) - Random variables
are mutually independent if, for any subset and any values , where ,
- Random variables
Mutual independence is an ideal condition of independence. The limited notion of independence is usually defined by the k-wise independence.
Definition (k-wise Independenc) - 1. Events
are k-wise independent if, for any subset with - 2. Random variables
are k-wise independent if, for any subset with and any values , where ,
- 1. Events
A very common case is pairwise independence, i.e. the 2-wise independence.
Definition (pairwise Independent random variables) - Random variables
are pairwise independent if, for any where and any values
- Random variables
Note that the definition of k-wise independence is hereditary:
- If
are k-wise independent, then they are also -wise independent for any . - If
are NOT k-wise independent, then they cannot be -wise independent for any .
Pairwise Independent Bits
Suppose we have
Enumerate all the nonempty subsets of
where
0 0 0 0 1 1 1 0 1 1 1 0
There are
.
Sometimes,
We claim that
Theorem - For any
and any , - For any
that and any ,
- For any
The proof is left for your exercise.
Therefore, we extract exponentially many pairwise independent uniform random bits from a sequence of mutually independent uniform random bits.
Note that
Pairwise Independent Variables
We now consider constructing pairwise independent random variables ranging over
Let
Theorem - The random variables
are pairwise independent uniform random variables over .
- The random variables
Proof. We first show that are uniform. That is, we will show that for any ,Due to the law of total probability,
For prime
, for any , there is exact one value in of satisfying . Thus, and the above probability is .We then show that
are pairwise independent, i.e. we will show that for any that and any ,The event
is equivalent to thatDue to the Chinese remainder theorem, there exists a unique solution of
and in to the above linear congruential system. Thus the probability of the event is .
Universal Hashing
Hashing is one of the oldest tools in Computer Science. Knuth's memorandum in 1963 on analysis of hash tables is now considered to be the birth of the area of analysis of algorithms.
- Knuth. Notes on "open" addressing, July 22 1963. Unpublished memorandum.
The idea of hashing is simple: an unknown set
This idea seems clever: we use a consistent mapping to deal with an arbitrary unknown data set. However, there is a fundamental flaw for hashing.
- For sufficiently large universe (
), for any function, there exists a bad data set , such that all items in are mapped to the same entry in the table.
A simple use of pigeonhole principle can prove the above statement.
To overcome this situation, randomization is introduced into hashing. We assume that the hash function is a random mapping from
Simple Uniform Hash Assumption (SUHA or UHA, a.k.a. the random oracle model):
- A uniform random function
is available and the computation of is efficient.
Families of universal hash functions
The assumption of completely random function simplifies the analysis. However, in practice, truly uniform random hash function is extremely expensive to compute and store. Thus, this simple assumption can hardly represent the reality.
There are two approaches for implementing practical hash functions. One is to use ad hoc implementations and wish they may work. The other approach is to construct class of hash functions which are efficient to compute and store but with weaker randomness guarantees, and then analyze the applications of hash functions based on this weaker assumption of randomness.
This route was took by Carter and Wegman in 1977 while they introduced universal families of hash functions.
Definition (universal hash families) - Let
be a universe with . A family of hash functions from to is said to be -universal if, for any items and for a hash function chosen uniformly at random from , we have
- A family of hash functions
from to is said to be strongly -universal if, for any items , any values , and for a hash function chosen uniformly at random from , we have
- Let
In particular, for a 2-universal family
For a strongly 2-universal family
This behavior is exactly the same as uniform random hash functions on any pair of inputs. For this reason, a strongly 2-universal hash family are also called pairwise independent hash functions.
2-universal hash families
The construction of pairwise independent random variables via modulo a prime introduced in Section 1 already provides a way of constructing a strongly 2-universal hash family.
Let
and the family is
Lemma is strongly 2-universal.
Proof. In Section 1, we have proved the pairwise independence of the sequence of , for , which directly implies that is strongly 2-universal.
- The original construction of Carter-Wegman
What if we want to have hash functions from
Suppose that the universe is
and the family
Note that unlike the first construction, now
Lemma (Carter-Wegman) is 2-universal.
Proof. Due to the definition of , there are many different hash functions in , because each hash function in corresponds to a pair of and . We only need to count for any particular pair of that , the number of hash functions that .We first note that for any
, . This is because would imply that , which can never happen since and (note that for an ). Therefore, we can assume that and for .Due to the Chinese remainder theorem, for any
that , for any that , there is exact one solution to satisfying:After modulo
, every has at most many that but . Therefore, for every pair of that , there exist at most pairs of and such that , which means there are at most many hash functions having for . For uniformly chosen from , for any ,We prove that
is 2-universal.
- A construction used in practice
The main issue of Carter-Wegman construction is the efficiency. The mod operation is very slow, and has been so for more than 30 years.
The following construction is due to Dietzfelbinger et al. It was published in 1997 and has been practically used in various applications of universal hashing.
The family of hash functions is from
and the family
This family of hash functions does not exactly meet the requirement of 2-universal family. However, Dietzfelbinger et al proved that
So
The function is extremely simple to compute in c language.
We exploit that C-multiplication (*) of unsigned u-bit numbers is done
h_a(x) = (a*x)>>(u-v)
The bit-wise shifting is a lot faster than modular. It explains the popularity of this scheme in practice than the original Carter-Wegman construction.