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.

HardTechnical
58 practiced

A production backend experienced a latency spike and long GC pauses. Profiling shows frequent large HashMap resizing causing many allocations and long mark-sweep pauses. How would you investigate the root cause and propose fixes to reduce GC impact and rehash overhead (for example pre-sizing maps, using primitive collections, off-heap storage, or batching inserts)?

HardTechnical
64 practiced

Explain how equals() and hashCode() in Java interact and why inconsistent implementations can break hash-based caches and maps. Describe strategies to design key classes for caches which must remain stable across application versions and survive serialization, including avoiding volatile fields and using explicit versioning of key formats.

HardTechnical
78 practiced

Implement a HashSet in Java using open addressing with linear probing. Provide methods add(E key), contains(E key), and remove(E key). Ensure correct handling of tombstones, resizing, and rehashing. Discuss how you will avoid clustering and maintain performance as load factor grows.

EasyTechnical
72 practiced

Explain the concept of load factor in hash tables and how it affects performance and memory usage. Describe the resize (rehash) operation when capacity is doubled and provide an amortized analysis showing that average insertion cost remains O(1). Discuss trade-offs of different resize thresholds (e.g., 0.5 vs 0.75).

HardTechnical
55 practiced

Describe minimal perfect hashing and algorithms (e.g., BDZ, CHD) for constructing space-efficient static maps. Explain time and space complexities, construction cost, and practical use cases such as mapping a large static vocabulary to contiguous IDs for embedding tables in ML systems.

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.