DSAVisualiseData Structures & Algorithms Studio
Hash Tables Hard

Separate Chaining

A hash function chooses a bucket. A linked chain stores different keys that land in the same bucket.
Load factor α0.00
Capacity 5Entries 0

Operations

Console
Try a scenario

Key stream

Complexity

Per operation
BestO(1)
AverageO(1 + α)
WorstO(n)

Expected constant time with a well-distributed hash.

SpaceO(n + m)

Diagram legend

Active bucketCollisionLinked entryMatch found

Hash pipeline

Java String
Input“98”
hashCode()—
& 0x7fffffff—
mod capacity—

Bucket array st[]

Linked nodes share a bucket when their hashes collide.

Memory view

Choose a scenario to follow the structure.

Why this worksConcept & common mistakes

A hash function chooses a bucket. Separate chaining stores every key assigned to that bucket in a linked chain. To insert, look up, or remove a key, compare the complete key at each node.

Worked example. Java hashes "11" to 1568 and "98" to 1823. Both have remainder 3 modulo 5. Inserting 98 → dog beside 11 → cat creates two distinct nodes in bucket 3.

  • A shared bucket is a collision, so compare the full key.
  • Replacing a value keeps the same node and entry count.
  • Removing the head must update the bucket pointer.
  • Resizing must recompute every key’s bucket index.

Algorithm code

Java
SeparateChaining.javaStep linked
Loading lesson source…
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1
Comparisons 0 · Collisions 0

Understand your operation

Scroll to follow how your operation changes the table.

Explore detailed execution

Every row is a meaningful action from this stored run. Select one to inspect its saved state and optional Java reference.

    Ready for another operation?

    Return to the interactive table and try a different key.

    Back to the theater