Hash Table
Maps keys to bucket indices with a hash function to store and look up in average O(1). When different keys collide into the same bucket, it resolves them with chaining (linked lists) or open addressing.
01Hash Table
Explore How It WorksHash table. A hash function (here key % 5) computes the key's bucket number.
put(10) · 10 % 5 = 0. Put 10 in bucket 0.
put(24) · 24 % 5 = 4. Put 24 in bucket 4.
put(14) · 14 % 5 = 4. Collision in bucket 4, which already holds 24 — chain 14 after 24.
put(3) · 3 % 5 = 3. Put 3 in the empty bucket 3.
get(14) · Jump straight to bucket 14 % 5 = 4. Scan the chain: 24 (no) → 14 (match) is found.
The bucket number is computed in one step, so average O(1). Collisions are resolved by chaining, with only a short search inside that bucket.
02 Understand It Simply
For EveryoneA hash function turns the key into a slot number, so insertion and lookup go directly to that slot. Collisions are resolved within the slot.
Computes the storage location straight from the key.
No searching — it finds items almost instantly (average O(1)).
When cells collide, it chains them together.
- –Dictionaries/maps
- –duplicate checks
- –database indexes
- –caches
03 Python Implementation
A clean, readable reference implementation of the core logic of Hash Table.
04 Frequently Asked Questions
FAQWhat is Hash Table?+
Maps keys to bucket indices with a hash function to store and look up in average O(1). When different keys collide into the same bucket, it resolves them with chaining (linked lists) or open addressing.
What is the time complexity of Hash Table?+
The time complexity of Hash Table is Avg O(1). Follow the step-by-step visualization to see exactly why.
Where is Hash Table used?+
Dictionaries/maps, duplicate checks, database indexes, caches.
What's a simple analogy for Hash Table?+
A hash function turns the key into a slot number, so insertion and lookup go directly to that slot. Collisions are resolved within the slot.
