Implement and analyse hash tables

8 steps · about 4 h 35 min · Intermediate

  1. Model the hash-table operations (guide, Wikipedia, 35 min)

    Relate keys, buckets, hashes and equality to lookup, insertion and deletion.

  2. Choose a hash function contract (guide, Wikipedia, 30 min)

    Require stable equal-key hashes and useful distribution without confusing hashing with encryption.

  3. Implement separate chaining (guide, Wikipedia, 40 min)

    Resolve collisions with per-bucket collections and measure how chain length changes.

  4. Implement open addressing (guide, Wikipedia, 40 min)

    Explore probe sequences, empty markers and deletion without auxiliary chains.

  5. Track load factor (guide, Wikipedia, 30 min)

    Connect occupancy to collision frequency, probe length and memory cost.

  6. Analyse resizing cost (guide, Wikipedia, 35 min)

    Explain why occasional full rehashes can still yield bounded average insertion cost.

  7. Test adversarial collisions (guide, Wikipedia, 30 min)

    See how poor or hostile key distributions can collapse expected constant-time behaviour.

  8. Compare with an ordered map (guide, Wikipedia, 35 min)

    Choose between expected constant lookup and ordered worst-case logarithmic operations for the real workload.