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

The Problem

How do we know when a hash table is “too full” and performance will degrade? We need a metric to decide when to resize.

Core Idea

Load factor (α) is the ratio of elements stored to the total table size: α = number_of_elements / table_size. It predicts hash table performance.

How It Works

  1. Calculate α = n / m (n = elements, m = table size)
  2. α ≤ 0.7: good performance, few collisions
  3. α > 0.7: performance drops, consider resizing
  4. α close to 1.0: many collisions, O(n) worst case likely
load_factor Good α = 0.5 Good performance O(1) avg Okay α = 0.7 Okay, monitor Good->Okay insert more elements Bad α = 0.9 Bad, resize! O(n) worst Okay->Bad insert more elements

Key Properties

  • α = 0.0: empty table (wasted space)
  • α = 0.5-0.7: sweet spot for performance
  • α > 0.7: collisions increase sharply
  • α = 1.0: table full, must resize

Connections

Edge Cases & Gotchas

  • Low load factor wastes memory (too many empty slots)
  • High load factor causes performance collapse
  • Resizing requires rehashing ALL elements (expensive)
  • Chaining tolerates higher load factors than probing