Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Hash Table

1 topic · 28 Nov 2026
1

Hash Table

Data Structure

A hash table maps keys to values using a hash function that turns a key into an array index. Two keys with the same index cause a collision.

  • Chaining — each slot keeps a list of entries.
  • Open addressing — find another free slot (linear probing, quadratic probing, double hashing).
  • Load factor = items / slots; when it gets high the table is resized (rehashing).

Collision handled by chaining

Collision handled by chaining

Counting frequency with a hash map · C++
unordered_map<string, int> freq;
for (string w : {"a", "b", "a", "c", "a"})
    freq[w]++;
cout << freq["a"];   // 3