Data Structures & Algorithms · Interview question

What is a collision and how do you resolve it?

A strong answer

A collision is when two distinct keys hash to the same bucket, unavoidable in general, because there are more possible keys than buckets (pigeonhole principle). Two standard resolutions. Chaining: each bucket holds a linked list (or small structure) of all keys that hashed there; on collision you append, and lookup scans that short list. Open addressing: store one key per slot, and on collision probe for another slot, linear probing tries the next slots in sequence (i+1, i+2, … wrapping), quadratic probing and double hashing use other step patterns to reduce clustering. The tradeoff: chaining handles high load factors more gracefully and makes deletion simple but needs a node allocation per key (heap or pool) and pointer-chasing; open addressing keeps everything in one contiguous array (no per-key allocation, cache-friendly) but degrades sharply as it fills and needs tombstones for deletion.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Hash Tables

O(1)-average keyed lookup by mapping keys to array slots: collisions, load factor, and why open addressing into a fixed array beats chaining when you have no heap.

More Hash Tables questions

Browse all 472 interview questions
What is a collision and how do you resolve it? | EmbeddedPrep.io