You have 3 free guides left 😟
Unlock your guides
You have 3 free guides left 😟
Unlock your guides

9.2 Collision Resolution Techniques

2 min readjuly 19, 2024

Hash tables are powerful data structures for fast key-value lookups. However, collisions occur when multiple keys map to the same index. This intro explores collision resolution techniques, crucial for maintaining hash table efficiency.

We'll cover and methods, examining their pros and cons. We'll also discuss 's impact on performance and how to choose the best strategy for your specific use case.

Hash Table Collision Resolution

Collisions in hash tables

Top images from around the web for Collisions in hash tables
Top images from around the web for Collisions in hash tables
  • Two or more keys generate the same hash value and map to the same index ()
  • Inevitable due to the pigeonhole principle: n items, m slots, n > m, at least one slot contains multiple items
  • Degrade hash table performance by requiring additional work to resolve collisions
  • Collision frequency increases with more elements, reducing hash table efficiency

Collision resolution techniques

  • Chaining (separate chaining) stores colliding elements in a linked list at each hash table index
    • Allows unlimited elements, O(1 + α), α = load factor (n/m)
  • Open addressing stores colliding elements in alternative hash table slots
    • Probing sequence finds the next available slot
      1. : search next slot linearly (h(k) + i) mod m, i = 0, 1, 2, ...
      2. : quadratic function for next slot (h(k) + i^2) mod m, i = 0, 1, 2, ...
      3. : second determines probing sequence h2(k) = r - (k mod r), r = prime < table size
    • Requires load factor < 1 to ensure empty slots for collision resolution

Load factor and efficiency

  • Load factor (α) = number of elements (n) / hash table size (m)
  • Affects collision probability and hash table efficiency
  • Higher load factor → more collisions, expected collisions for a key proportional to α
  • Lower load factor (α ≤ 0.5) fewer collisions but more space
  • Higher load factor (α ≥ 0.7) more collisions but efficient space utilization
  • Practical load factor 0.5 to 0.75 balances space and time efficiency

Choosing resolution strategies

  • Consider expected elements, key distribution, memory constraints, performance requirements
  • Chaining suits unknown/growing element count, ample memory, frequent insertions/deletions
  • Open addressing suits known element count ≤ table size, limited memory, faster search/retrieval
  • Hybrid approaches combine chaining and open addressing to balance advantages/disadvantages
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.

© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.
Glossary
Glossary