Hash Tables — Separate Chaining

Explore insertion, lookup, and deletion. Each table position points to a linked list (chain) of keys that hash to that position. Choose the exact operations and their order.
Setup Step 1
Choose a sequence of operations, then step through the algorithm.
Operation sequence
The operations are performed from left to right. Green means completed; yellow marks the current operation.
Hash table — buckets and linked lists
Stored key Node being inspected Inserted / matching key → follows the next pointer
Hash calculation and chain traversal
No operation selected yet.
Nodes examined
No nodes examined yet.
Use +k to insert key k, −k to delete it, and ?k to search for it. Separate operations with commas. Keys must be non-negative integers; table size can be 3–16.
How separate chaining works

Compute h(k) = k mod m to choose a bucket. If other keys have the same hash value, they are stored in the same bucket's linked list. A collision therefore adds another node to that chain; it does not require probing another table position.

This animation inserts new keys at the head of the linked list. Before inserting, it traverses the chain to avoid inserting a duplicate key. Search and deletion also follow the chain one node at a time; deletion unlinks the matching node.

With a good hash function and a controlled load factor, operations take expected O(1) time. More precisely, traversal takes expected O(1 + α), where α = n/m is the average number of keys per bucket. In the worst case, all keys may land in one bucket, giving O(n) operations.