Data Structures & Algorithms · Revision notes

Hashing & Hash Tables

A hash table maps keys to array indices using a hash function, giving average O(1) insert, search and delete. Collisions are resolved by chaining or open addressing; hash maps/sets turn many O(n^2) scans into O(n).

Quick revision

  • h(k)=k mod m (prime m); load factor alpha = n/m; resize at ~0.75, amortized O(1)
  • Chaining: Theta(1+alpha); open addressing needs alpha<1, tombstones for delete
  • Linear: primary clustering; quadratic: secondary; double hashing best
  • Two-sum: lookup complement before inserting; prefix-sum map; group by canonical key
  • Average O(1), worst O(n)
Read the full Hashing & Hash Tables notes on Doubtclip →