Hash Tables and Near-Constant Lookup · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Jump to the answer by calculation

Computing · Algorithms & Data Structures · ages 16-18
Name ______________________   Date ____________
  1. A key with hash value 10 joins a 7 slot table. Which slot takes it?

    • slot 10
    • slot 7
    • slot 3
  2. What does the hash function turn a key into?

    • a slot number to jump to
    • a sorted position in order
    • a second copy of the value
  3. The same key always hashes to the same slot.

    Circle one:   True   False

  4. Under linear probing, a key hashes to slot 4 but slot 4 is taken. What happens on insert?

    • the taken slot is cleared first
    • the key is dropped
    • the walk moves forward to the next free slot
  5. Two keys land in one slot under chaining. Where does the second key go?

    • it overwrites the first key
    • it joins the small list inside that slot
    • it moves to a second table
  6. Five keys hash into ten slots with one collision. Why does this still beat checking every entry?

    • every key lands in slot zero together
    • most lookups jump near the answer with only a short clash to settle
    • collisions sort the keys for free
  7. A friend inserts with probing but looks up by jumping only to the hashed slot. Lookups miss keys that are present. What is wrong?

    • probing works for insert only
    • the table needs wider slots
    • lookup must repeat the same forward walk as insert
  8. A table with 10 slots holds 9 keys and lookups crawl. One chain holds 5 keys. What is the diagnosis?

    • the table is crowded, so clashes piled into long chains
    • the hash values are too small to store
    • chaining forgot the slot numbers
LightMySky · lightmysky.comW1-mt_7v94MJEdmJ-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Jump to the answer by calculation W1-mt_7v94MJEdmJ-s1

  1. slot 3 · Take the remainder: 10 divided by 7 leaves 3.
  2. a slot number to jump to · The table calculates where the answer lives instead of searching for it.
  3. True · Repeatable landing is what makes the jump trustworthy.
  4. the walk moves forward to the next free slot · Probing steps forward until free, and lookup repeats that same walk.
  5. it joins the small list inside that slot · Chaining queues clashing keys in the slot list, and lookup scans it.
  6. most lookups jump near the answer with only a short clash to settle · Calculation replaces the search, and one short clash costs far less than scanning all.
  7. lookup must repeat the same forward walk as insert · Both trips must follow one rule. A jump-only lookup never visits the walked-to slot.
  8. the table is crowded, so clashes piled into long chains · Crowding turns the jump into a search down long chains.
Worksheet · LightMySky