Learn VisualLearn CS

How Hash Tables Work

A hash table stores each key in the bucket numbered by a hash function — for example key % 5. When different keys map to the same bucket number, it is called a collision, and colliding keys are chained together in a linked list within that bucket.

GOAL

Explain how a hash function maps a key to a bucket number, and how collisions are resolved by chaining.

Inserting key 18, which bucket number does it land in?