Hashing and Hash Tables Questions

How hash tables and hash-based structures work internally, and how to reason about their performance and correctness. Covers hash function properties (determinism, uniform distribution, speed, avalanche effect), cryptographic versus non-cryptographic hash choices, collision resolution (separate chaining, open addressing: linear probing, quadratic probing, double hashing, Robin Hood hashing, cuckoo hashing), load factor and amortized-cost resizing, and what makes an object hashable (the __hash__/__eq__ contract, immutability, custom composite keys). Covers hash-map-backed cache design (LRU and LFU eviction, TTL) and thread-safe concurrent hash maps (lock striping, CAS-based updates, safe concurrent resizing). Also covers hash-based structures beyond arrays and strings: consistent hashing for distributed routing and sharding, hash joins, hash-flooding and algorithmic-complexity security attacks and their mitigations, and probabilistic membership/cardinality structures such as Bloom filters, Cuckoo filters, Count-Min Sketch, and HyperLogLog. Excludes using a hash map purely as an optimization trick inside an array or string problem (two-sum, group anagrams, longest substring without repeating characters); that pattern belongs to Arrays, Strings, and Hashing. This topic is about the hash table itself: how it is built, how it fails under skewed or adversarial input, and how it scales.

EasyTechnical
72 practiced

Explain why hash tables provide average-case O(1) for lookup, insertion, and deletion, but can degrade to O(n) in worst-case scenarios. Provide examples of input patterns causing worst-case behavior and explain how modern implementations mitigate this (for example, Java 8 switching to balanced trees when buckets become large).

MediumTechnical
54 practiced

You must maintain approximate counts of frequent items from a high-rate stream using limited memory. Compare exact hash-map counting to Count-Min Sketch and Lossy Counting. Describe error guarantees, mergeability, update time, and when approximate counting is acceptable in an AI feature extraction pipeline.

HardTechnical
61 practiced

Implement from scratch a HashMap class in Java that uses open addressing with quadratic probing. It must support put(key, value), get(key), and remove(key), handle tombstones for deletes, resize when load factor exceeds 0.6, and provide amortized O(1) operations. You do not need to implement concurrency. Explain your collision resolution choices and memory implications.

MediumTechnical
53 practiced

You're deduplicating JSON objects in a Python ETL job but records are Python dicts (unhashable). Describe approaches to make them usable as keys in a set/dict: canonical serialization (e.g., deterministic JSON), converting to sorted tuples, or computing stable fingerprints (e.g., SHA256). Discuss performance, correctness, and edge cases (ordering, floating point, missing fields).

HardTechnical
61 practiced

Provide a formal argument proving that using dynamic array doubling (capacity *= 2) for hash table capacity yields amortized O(1) insertion cost. Analyze alternative growth factors (for instance 1.5x) and their impact on both time (amortized cost) and space (wasted capacity). Discuss when a smaller growth factor may be preferable for memory-limited services.

Unlock Full Question Bank

Get access to all Hashing and Hash Tables interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.