# What Is Collision in Hashing in Data Structure?

//

Scott Campbell

In data structures, collision refers to a situation where two or more elements are assigned the same location or index in a hash table. Hashing is a technique used to store and retrieve data efficiently, and collisions can occur due to the limited number of available slots or buckets in a hash table.

## Understanding Hashing

Hashing is a process that converts data into a fixed-size value called a hash code or hash value. This value is used as an index to store and retrieve the data in a hash table. The aim of hashing is to distribute the data evenly across the available slots in the table, minimizing collisions and optimizing search operations.

## Types of Hash Functions

A hash function takes an input (data) and produces a unique output (hash code) of fixed size. There are various types of hash functions, including:

• Division Method: This method involves dividing the key by the size of the hash table and using the remainder as the hash code.
• Multiplication Method: In this method, the key is multiplied by a constant, and then fractional part of the product is used as the hash code.
• Folding Method: This method involves dividing the key into equal-sized parts (usually by digit grouping) and adding those parts together to obtain the hash code.

## Collision Resolution Techniques

Despite efforts to distribute data evenly, collisions can still occur due to limited space in the hash table. When two or more elements generate the same hash code, collision resolution techniques are employed to handle these situations effectively. Some common collision resolution techniques include:

• Chaining: Chaining involves creating a linked list at each slot of the hash table. When a collision occurs, new elements are appended to the linked list at the corresponding slot.
• Open Addressing: In open addressing, when a collision occurs, an alternative empty slot is found within the hash table using a specific probing sequence.

The element is then inserted in the first available slot.

• Linear Probing: Linear probing is a simple open addressing technique where elements are sequentially checked for an empty slot until one is found.
• Quadratic Probing: Quadratic probing uses a quadratic function to determine the next available slot in case of a collision. It provides better distribution and avoids primary clustering.

## The Impact of Collisions

Collisions can impact the performance and efficiency of hashing algorithms. If collisions occur frequently, it can lead to reduced search efficiency as more time is required to locate elements. Additionally, collisions may result in increased memory consumption due to chaining or open addressing techniques used for collision resolution.

### Conclusion

In conclusion, collisions in hashing occur when two or more elements are assigned the same location in a hash table. Hashing is an essential technique for efficient storage and retrieval of data. Understanding collision resolution techniques helps ensure optimal performance and minimizes search time in data structures.