Data Structures Β· Visualization

Hash Table: Collision Handling (Open Addressing)

Hash Table

Open addressing resolves collisions by probing for the next available slot within the array itself (no extra lists), using a probing sequence such as linear probing, quadratic probing, or double hashing until an empty slot is found. Time: Average O(1) with low load factor, degrades toward O(n) as the table fills up. Space: O(n).

Big-O: Average O(1) per operation; worst case O(n) on collisions.

Hash Table: Collision Handling (Open Addressing)

Hash Table

Open addressing resolves collisions by probing for the next available slot within the array itself (no extra lists), using a probing sequence such as linear probing, quadratic probing, or double hashing until an empty slot is found.

How Collision Handling (Open Addressing) Works

  1. Compute the initial slot: index = hash(key) % size.
  2. If that slot is occupied by a different key, apply the probe function to get the next candidate slot (e.g. linear: index+1, index+2, ...).
  3. Repeat probing until an empty slot (or the key itself, for updates) is found.
  4. For lookups, probe the same sequence until the key is found or an empty slot signals 'not present'.
  5. Deletions need special 'tombstone' markers so probing sequences aren't broken for later lookups.

Collision Handling (Open Addressing) Worked Example

Input: Insert 'dog' and 'god' which both hash to slot 2 in a table of size 7, using linear probing

  1. hash('dog') % 7 = 2 β†’ slot 2 empty β†’ place 'dog' at 2
  2. hash('god') % 7 = 2 β†’ slot 2 occupied β†’ probe slot 3 β†’ empty β†’ place 'god' at 3
  3. Lookup 'god': check slot 2 ('dog', no match) β†’ check slot 3 ('god', match)

Output: 'dog' at slot 2, 'god' at slot 3; lookup takes 2 probes

Try your own input
Hash Table: Introduction
Runs each key through a hash function to compute a bucket index, so lookups don’t need to scan every entry.
0
βˆ…
1
βˆ…
2
βˆ…
3
βˆ…
4
βˆ…
5
βˆ…
6
βˆ…
Active Hash map Key
Hash Table: Introduction
Press β–Ά Run to watch it step by step.
Python Β· Hash Tables in Code
# Hash map: key -> value, O(1) average
scores = {}
scores["alice"] = 90     # insert
v = scores.get("bob", 0) # get with default
del scores["alice"]      # delete

if "bob" in scores:      # membership
    print("present")
# example: openaddr key=dog
Input: Insert 'dog' and 'god' which both hash to slot 2 in a table of size 7, using linear probing

Behind the Scenes Execution

Press β–Ά Run in the visualizer β€” the call stack, registers and memory will replay here in sync with the code, line by line.

Collision Handling (Open Addressing) Time & Space Complexity

TimeAverage O(1) with low load factor, degrades toward O(n) as the table fills up
SpaceO(n)

When to Use Collision Handling (Open Addressing)

  • Cache-friendly hash maps (Python dict, Rust HashMap)
  • Memory-constrained embedded systems avoiding pointer overhead

Recommended resourcesAffiliate links Β· may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice β€” pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from β€” great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired β€” free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action β€” visualize the algorithms that operate on these structures, or take a guided course.