# Collision Resolution Techniques

Collision Resolution Techniques

### Collision in hashing

1. In this, the hash function is used to compute the index of the array.
2. The hash value is used to store the key in the hash table, as an index.
3. The hash function can return the same hash value for two or more keys.
4. When two or more keys are given the same hash value, it is called a collision. To handle this collision, we use collision resolution techniques.

### Collision resolution techniques

There are two types of collision resolution techniques.

1. Separate chaining (open hashing)

### Separate chaining

In this technique, a linked list is created from the slot in which collision has occurred, after which the new key is inserted into the linked list. This linked list of slots looks like a chain, so it is called separate chaining. It is used more when we do not know how many keys to insert or delete.

#### Time complexity

1. Its worst-case complexity for searching is o(n).
2. Its worst-case complexity for deletion is o(n).

1. It is easy to implement.
2. The hash table never fills full, so we can add more elements to the chain.
3. It is less sensitive to the function of the hashing.

1. In this, cache performance of chaining is not good.
2. The memory wastage is too much in this method.
3. It requires more space for element links.

Open addressing is collision-resolution method that is used to control the collision in the hashing table. There is no key stored outside of the hash table. Therefore, the size of the hash table is always greater than or equal to the number of keys. It is also called closed hashing.

The following techniques are used in open addressing:

1. Linear probing
3. Double hashing

### Linear probing

In this, when the collision occurs, we perform a linear probe for the next slot, and this probing is performed until an empty slot is found. In linear probing, the worst time to search for an element is O(table size). The linear probing gives the best performance of the cache but its problem is clustering. The main advantage of this technique is that it can be easily calculated.