• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Quadratic probing still has secondary clustering (keys with same initial hash follow same probe sequence). We need a way to give each key a unique probe sequence.

Core Idea

Double hashing uses two hash functions: the second hash determines the step size for probing, giving each key a unique probe sequence.

How It Works

  1. Compute h₁(k) = initial position
  2. Compute h₂(k) = step size (must be non-zero)
  3. Probe sequence: h₁(k), h₁(k)+h₂(k), h₁(k)+2h₂(k), …
  4. Each key has different step size → different probe sequence
doublehash K Key k H1 h₁(k) = 3 K->H1 H2 h₂(k) = 5 K->H2 Seq Probe: 3, 8, 13, 18... H1->Seq H2->Seq step size

Key Properties

  • Best open addressing method (least clustering)
  • Probes all slots if table size is prime and h₂(k) is non-zero
  • More computation (two hash functions)
  • Step size must be non-zero and relatively prime to table size

Connections

Edge Cases & Gotchas

  • h₂(k) must never be 0 (would infinite loop)
  • Table size should be prime for complete coverage
  • Most complex to implement of the three probing methods