Hash Table
A hash table maps keys to a bucket array via a hash function, providing average O(1) lookup/insert/delete; it is among the most used data structures.
Purpose
To provide average constant-time key-value access, efficiently implementing dictionaries and sets.
Mechanism
hash(key) % capacity locates the bucket. Collision handling: separate chaining (bucket holds a list) or open addressing (probe for the next empty slot). Load factor = element count / bucket count; exceeding a threshold triggers resizing and rehash. A good hash function distributes keys uniformly.
Use cases
- Dictionary and map implementations
- Database indexes
- Caches (LRU)
- Deduplication and sets
Examples
- Input
{"name":"Ada"} → hash("name")=5OutputValue stored in bucket 5O(1) on average
Common errors
- A poorly distributed hash function causes collision pile-ups
- Use a high-quality hash function and a suitable load factor
Related terms
Bloom Filter
A Bloom filter approximates set membership with k hash functions and a bit array, offering space efficiency at the cost of a false-positive rate. GLOSSARY
Big O Notation
Big O notation describes the asymptotic upper bound of a function, used to analyze algorithm time/space complexity while ignoring constants and lower-order terms. GLOSSARY
Related tools
Djb2
Djb2 — pure client-side tool. Privacy-first, no server round-trip. TOOL
Sdbm
Sdbm — pure client-side tool. Privacy-first, no server round-trip. TOOL
Zobrist
Zobrist — pure client-side tool. Privacy-first, no server round-trip. TOOL
Pearson
Pearson — pure client-side tool. Privacy-first, no server round-trip. TOOL
Elfhash
Elfhash — pure client-side tool. Privacy-first, no server round-trip. TOOL