{
  "slug": "universal-hashing",
  "term": "Universal hashing",
  "aliases": [
    "Universal hash family",
    "Universal2 hashing"
  ],
  "definition": "Universal hashing selects a hash function at random from a family with a bounded collision probability for every fixed pair of distinct keys.",
  "note": "For a range of m values, universality requires Pr[h(x) = h(y)] <= 1/m for each fixed x != y, with probability over the randomly chosen function h. The keys are independent of that choice. This is an average over functions, not a worst-case promise for the chosen function. [carter-wegman] [thorup]\n\nWith n stored keys and a fixed absent query, the expected number of stored keys in its bucket is at most n/m. A chained table still compares keys to resolve bucket collisions; expected bucket occupancy is not an exact-membership guarantee from the hash alone. [thorup]\n\nA finite example maps three input bits to two output bits using a random binary matrix. All 28 distinct key pairs collide under exactly 16 of the 64 matrices, yet the zero key always maps to zero. Adding an independent, uniform two-bit offset gives 256 affine maps and uniform, independent outputs for each pair. [hesela-example]\n\nStrong universality requires each ordered output pair to occur with probability 1/m^2 for distinct input keys. Plain universality does not require that stronger property. Nor does it promise collision resistance: in the finite example, choosing a colliding pair after seeing the matrix succeeds for every matrix. [thorup] [hesela-example]",
  "status": "shipping",
  "advantages": [],
  "limitations": [
    {
      "text": "A pairwise collision bound alone does not supply all independence assumptions needed by other randomized data structures.",
      "citationIds": [
        "thorup"
      ]
    }
  ],
  "related": [
    "hash-collision",
    "minimal-perfect-hash-function",
    "bloom-filter",
    "cryptographic-hash"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-10",
  "citations": [
    {
      "id": "carter-wegman",
      "title": "Carter and Wegman. Universal Classes of Hash Functions. JCSS 18(2), 143-154 (1979). DOI: 10.1016/0022-0000(79)90044-8.",
      "url": "https://bpb-us-w2.wpmucdn.com/u.osu.edu/dist/7/36891/files/2020/10/CarterWegmanJrCompSci1979UniversalHashClasses.pdf",
      "accessed": "2026-11-10"
    },
    {
      "id": "thorup",
      "title": "Thorup. High Speed Hashing for Integers and Strings. arXiv:1504.06804v9 (2020), sections 2, 2.1, 3 and 6.",
      "url": "https://arxiv.org/pdf/1504.06804v9",
      "accessed": "2026-11-10"
    },
    {
      "id": "hesela-example",
      "title": "Hesela: exhaustive binary-matrix hashing example, including output bias and fixed-versus-adaptive pairs.",
      "url": "https://hesela.dev/research/universal-hashing/README.md",
      "accessed": "2026-11-10"
    }
  ],
  "provenance": [
    "The finite example enumerates every seed and input pair in a toy family; it is a mathematical demonstration, not a storage benchmark or security evaluation."
  ]
}
