What is a hash table / hash map?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Data Structures & Algorithms basics — a prerequisite for any developer role.
Answer
A hash table (hash map) is a data structure that provides O(1) average time for insert, delete, and lookup by using a hash function to map keys to array indices. The hash function converts a key to an integer, then maps it to a bucket/slot (index = hash(key) % capacity). Collisions occur when two keys hash to the same index. Collision resolution: (1) Chaining — each bucket is a linked list; O(1) average, O(n) worst (all keys in one chain); (2) Open addressing — find the next available slot: linear probing, quadratic probing, double hashing. Load factor: n/m (n = elements, m = buckets). When load factor exceeds a threshold (~0.75), resize (rehash) — O(n) amortized. Operations: Insert O(1) avg, O(n) worst; Lookup O(1) avg; Delete O(1) avg. Hash functions: should distribute keys uniformly and be fast to compute. Examples: DJB2, MurmurHash, SipHash. Java HashMap, Python dict, JavaScript Map are all hash maps. Use cases: counting frequencies, detecting duplicates, caching, implementing sets, graph adjacency lists, indexing. Hash maps are arguably the most useful and widely-used data structure in software engineering.
Common Mistake
Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Data Structures & Algorithms experience.