What is a hash collision in a hash table?

What is a hash collision in a hash table?

a) When two keys hash to the same index
b) When two keys have the same value
c) When two values occupy the same memory address
d) When two keys have the same length

Answer:

a) When two keys hash to the same index

Explanation:

A hash collision occurs in a hash table when two different keys produce the same hash value, meaning they are mapped to the same index. Since a hash table uses hash values to determine where to store or find data, collisions must be handled properly to avoid data loss.

Common techniques to handle hash collisions include chaining (storing multiple elements in the same index using a linked list) and open addressing (finding the next available slot in the table).

Good hash functions minimize the number of collisions by distributing keys uniformly across the hash table.

Reference:

DSA (Data Structures and Algorithms) MCQ Questions and Answers

Scroll to Top