WIPIVERSE All articles

Universal hashing

Universal hashing is a technique in computer science and information theory for designing hash functions. It is a family of hash functions from which a hash function is selected at random, with the goal of minimizing the probability of collisions between distinct keys regardless of the distribution of those keys.

Definition

A set H of hash functions mapping a universe of keys U to a table of size M is called a universal hash function family if, for any two distinct keys x and y in U, the probability that a randomly chosen function h from H maps both keys to the same value is at most 1/M:

Pr[h(x) = h(y)] ≤ 1/M

for all x ≠ y in U.

Properties

  • Collision resistance by design: The probability of collision between any pair of distinct keys is bounded by the reciprocal of the table size, ensuring that performance degrades gracefully even with adversarial or poorly distributed input.
  • Randomized selection: A hash function is chosen randomly from the family at initialization time, preventing an adversary from predicting which function will be used and crafting inputs that cause excessive collisions.
  • Expected constant-time operations: When a universal hash family is used, the expected number of collisions for any key is bounded, leading to expected O(1) time for insert, lookup, and delete operations in hash table implementations.

Construction

Several methods exist for constructing universal hash families, including:

  • Matrix method: For u-bit keys and a table of size M = 2^b, a random b × u binary matrix is selected. The hash of a key x is computed as the matrix-vector product over GF(2).
  • Multiplicative hashing: Uses a randomly chosen odd multiplier and modular arithmetic to produce hash values.
  • Polynomial hashing: Treats keys as coefficients of a polynomial evaluated at a random point modulo a prime.

Applications

Universal hashing is used in:

  • Hash table implementations where guaranteed average-case performance is required
  • Randomized algorithms that depend on low collision probabilities
  • Cryptographic constructions and data structures such as perfect hashing and sketching algorithms (e.g., MinHash)

Related concepts

  • Perfect hashing
  • Cuckoo hashing
  • Hash table
  • Randomized algorithm

The concept is well established in the algorithms literature, including standard textbooks such as Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein.

Browse

More topics to explore

    Browse all articles