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
77 practiced

Compare separate chaining and open addressing collision-resolution strategies (linear probing, quadratic probing, double hashing). Discuss cache locality, memory overhead, deletion complexity, primary clustering, probe length distribution, and which you'd choose for systems with constrained memory versus systems optimized for CPU caches.

HardTechnical
59 practiced

Explain hash collision (hash-flooding) attacks and their effect on hash-table-backed services. As a data engineer, what would you deploy at the application and infrastructure level to make your pipeline's hash tables resilient to an attacker who can choose input keys?

MediumTechnical
73 practiced

Given expected N=100 million items and a required false positive rate p=1%, compute the Bloom filter bit-array size m and number of hash functions k using standard formulas. Show numeric results, explain the derivation and discuss pros/cons of Bloom filters versus exact hash sets for membership testing.

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.

EasyTechnical
77 practiced

Implement a simple HashMap in Python with separate chaining. Provide a class with methods put(key, value), get(key) -> value or None, and remove(key). Assume keys are hashable. Keep implementation readable and aim for average O(1) operations. Include a brief complexity analysis and a couple of tiny tests demonstrating correctness.

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.