Building an FKS table #
The randomized construction of the Fredman–Komlós–Szemerédi table [FKS84],
in the form of [CLRS09], Section 11.5, for a duplicate-free list of n keys and a range-indexed
universal family F (∀ r, IsTwoUniversal (F.seed r) (F.hash r)):
- draw top seeds into
nvalues (rangen - 1) until the squared bucket sizes sum to at most4 n; - for each bucket of
bkeys, draw seeds intob²values (rangeb² - 1) until one is injective on the bucket.
Each attempt succeeds with probability at least 1 / 2 (Collisions: Markov's inequality for the
first level, and n² ≤ m for the second), so each level takes at most 2 attempts in expectation.
Cost model #
The construction is an OracleComp over the interface PerfectHashing.buildSpec F, whose calls are
draw r, a fresh seed of range r, and eval r s x, the value of the function of seed s at the
key x. Under the honest answers PerfectHashing.answer F a draw follows the seed law and an
evaluation returns the hash value. The model is abstract: it counts seed draws
(PerfectHashing.drawCost) and hash evaluations (PerfectHashing.evalCost), not word-RAM
instructions. Sorting keys into buckets, checking an attempt and laying out the memory are local
computation and are not charged; they use only the hash values the program obtained from its calls.
An oracle program is a finite tree of calls, so the unbounded Las Vegas loop is truncated: each
level makes at most fuel attempts (OracleComp.retry), and the construction returns none if
some level exhausts its fuel. The expected costs are bounded uniformly in fuel, and the
probability of none decays geometrically in fuel.
Main definitions #
PerfectHashing.Query,PerfectHashing.buildSpec,PerfectHashing.answer,PerfectHashing.drawCost,PerfectHashing.evalCost: the interface, its honest answers and its two costs.PerfectHashing.trial: draw a seed and evaluate it at every key.PerfectHashing.bucketOf,PerfectHashing.TopGood,PerfectHashing.SecGood: buckets from observed hash values, and the success tests of the two levels.PerfectHashing.buildSecondary,PerfectHashing.buildRest,PerfectHashing.build: the construction.
Main results #
PerfectHashing.valid_of_mem_support_build: every table the construction returns satisfies the FKS conditions, so it answers lookups correctly (PerfectHashing.runLookup_of_mem_support_build) in at most5 n + 2cells (PerfectHashing.size_le_of_mem_support_build).PerfectHashing.evalWith_build_none_le: the construction fails with probability at most(n + 1) 2^{-fuel}forn ≥ 1keys.PerfectHashing.expectedCost_build_draw_le: at most2 (n + 1)expected seed draws forn ≥ 1keys, whatever the fuel.PerfectHashing.expectedCost_build_eval_le: at most4 nexpected hash evaluations, whatever the fuel.
References #
The interface #
The calls of the construction: draw a seed of range r, or evaluate the function of a seed
at a key.
The interface of the construction.
One attempt #
The outcome of one attempt: a seed and the observed values of its function at the keys.
- seed : F.Seed r
The drawn seed.
The values of its function at the keys, in order.
One attempt: draw a seed of range r and evaluate it at every key.
The construction #
Build the block of a bucket: at most fuel attempts at a seed into b² values that is
injective on the bucket's b keys.
The FKS construction for the key list keys, with at most fuel attempts per level.
One attempt under the honest answers #
One attempt draws a seed and observes the values of its function.
Buckets from observed values #
Correctness #
Correctness of the construction. Under the honest answers, every table the construction returns for a duplicate-free key list satisfies the FKS conditions.
A table returned by the construction answers every lookup correctly.
A table returned by the construction for n keys occupies at most 5 n + 2 cells.
Failure probability and expected cost #
A top-level attempt into n values fails with probability at most 1 / 2 (Markov's
inequality on the expected squared bucket sizes, Collisions).
A secondary attempt into b² values on a duplicate-free bucket of b keys fails with
probability at most 1 / 2 (Collisions).
The block of a bucket is built except with probability 2^{-fuel} (always, for an empty
bucket and positive fuel).
After a successful top-level attempt, the blocks are all built except with probability
n 2^{-fuel} for n ≥ 1 keys (a union bound over the buckets).
Failure probability of the construction. With at most fuel attempts per level, the
construction for a duplicate-free list of n ≥ 1 keys fails with probability at most
(n + 1) 2^{-fuel}: 2^{-fuel} for the top level and 2^{-fuel} for each of the n buckets.
The block of a bucket costs at most twice one attempt in expectation, whatever the fuel.
Expected seed draws. The construction for a duplicate-free list of n ≥ 1 keys draws at
most 2 (n + 1) seeds in expectation, whatever the fuel: two expected attempts at the top level
and at each of the n buckets.
Expected hash evaluations. The construction for a duplicate-free list of n keys makes at
most 4 n hash evaluations in expectation, whatever the fuel: two expected attempts of n
evaluations at the top level, and two expected attempts of b_j evaluations at each bucket.