Skip to main contentSkip to solution

A perfect hash function maps every input key to _____________ in the hash table.

Solution

✅ Correct Option: 2

A perfect hash function maps each distinct key to a different slot, so no two keys share an index. This means there are no collisions, and lookup takes constant time without needing chaining or probing.


Options 1 and 3: similar or duplicate indices are exactly what a collision is, which a perfect hash function avoids.

A minimal perfect hash function goes further: it maps nn keys onto exactly nn slots with no empty ones.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question