The Runtime Theory
mediumRuntimeInternals#explain-the-model#reason-about-tradeoffs

Explain Hash Tables: From Keys to Buckets

Explain the model, execution steps, complexity, and limits of hash tables: from keys to buckets.

TRT practice prompt — not a verified question from a named employer.

The Runtime Theory Team6 min read

Interview prompt

Explain hash tables: from keys to buckets to an engineer who understands the surrounding system but has not used this technique. Walk from its contract to a concrete operation, then discuss where it fails or becomes expensive.

A strong answer

A hash table transforms a key into a hash value and uses part of that value to select a bucket or slot. The table then checks key equality because hashes can collide: equal hashes do not prove equal keys. Correctness therefore depends on both a stable hash/equality contract and collision handling.

With separate chaining, each bucket holds a collection of entries. With open addressing, collisions probe other slots according to a rule. As occupancy rises, probe sequences or bucket chains tend to grow, so implementations resize around a chosen load factor. Resizing reassigns entries because bucket positions depend on table capacity.

A complete answer also calls out the assumptions that control correctness. Expected constant-time lookup relies on assumptions about hash distribution and workload; adversarial keys can create long chains or probe clusters. Mutable keys are dangerous when their hash changes after insertion. Hash tables also do not inherently preserve sorted order and may use more memory than a compact array.

Close by describing one representative test or measurement. Explain why a map must compare the original key after a hash match. Then describe what goes wrong if a key object changes a field used by its hash after insertion.

Follow-up questions

Answer the follow-ups in the frontmatter. Use the linked article for the concept and the trace to make the explanation concrete.

This answer walks

Practice follow-ups

  1. 01Which assumption is essential for the approach to be correct?
  2. 02What is the worst case, and how does it change the resource cost?
  3. 03How would you adapt the design if the input or workload became much larger?
  4. 04What boundary test would give you the most confidence in the implementation?

One dispatch a week

The trace behind each question, the tradeoff that explains it, and one technical dispatch per week — no noise.

One technical dispatch per week. No noise.

Not started

Sign in to save your learning progress.

Sign in to save