DSAVisualiseData Structures & Algorithms Studio
Hash Tables Medium

Linear Probing

When two keys hash to the same slot, linear probing checks the next slot and wraps at the end of the array. The displayed Java fixes one upstream bug: put must compare keys with equals, not reference identity, or equal keys can be stored twice.
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—

Open-addressed keys[] array

Each key occupies one slot; collisions probe the next slot and wrap around.

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
LinearProbingHashST.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