Skip to content
uencoder

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")=5
    Output
    Value stored in bucket 5

    O(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

Related tools

References