What are hash table collisions? How is it avoided?

A hash table collision happens when two different keys hash to the same value. Two data cannot be stored in the same slot in array.

To avoid hash table collision there are many techniques, here we list out two

  • Separate Chaining:
  • It uses the data structure to store multiple items that hash to the same slot.
  • Open addressing:
  • It searches for other slots using a second function and store item in first empty slot that is found