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

The Problem

In separate chaining, we need extra memory for linked lists. Can we store everything in the hash table array itself by finding the next empty slot?

Core Idea

On collision, linear probing checks the next slot (index+1, +2, …) until an empty slot is found, wrapping around to the beginning if needed.

How It Works

  1. Hash key to get initial index
  2. If slot is empty, insert there
  3. If occupied, check next slot (index+1)
  4. Continue until empty slot found (wrap around if needed)
  5. Search: check slots sequentially until key found or empty slot
linear_probe T Hash Table S0 3: Alice T->S0 probe sequence S1 4: Bob ← probed here S0->S1 probe sequence S2 5: (empty) S1->S2 probe sequence

Key Properties

  • No extra memory for linked lists (all in array)
  • Causes primary clustering (consecutive occupied slots)
  • Probe sequence is: h(k), h(k)+1, h(k)+2, …
  • Deletion tricky: need tombstone markers

Connections

Edge Cases & Gotchas

  • Primary clustering: long runs of occupied slots form
  • Performance drops sharply when load factor > 0.7
  • Deletion needs tombstones (can’t just clear slot)
  • Table must be resized when getting full