Skip to content

Hash table with double hashing

storing

Level 2 of 3

Also called Double hashing and Open addressing with a second hash.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from hash table with double hashing's own run on the numbers shown.

choose one

question 1

An empty table of 7 slots puts in 33, 5, 61, 47 and 89, all with home 5. How many probes do the five puts make in all?

the answer, and why

the answer is C

33 takes slot 5, 1 probe. Each of the others has its own step, 1, 2, 3, 5, and finds slot 5 taken, then a free slot. 1 + 2 + 2 + 2 + 2 is 9.

if you chose another

  • That walks one slot on each time, as linear probing does, 1 + 2 + 3 + 4 + 5.
  • That counts 1 probe a put, but each after 33 finds slot 5 taken.
  • That counts 2 probes for 33 too, but its home is free.

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 22 and 15, then 8. Which slot does 8 go in?

the answer, and why

the answer is A

22 takes slot 1. 15, home 1 and step 1, takes slot 2. 8 has home 1 and step 4. Slot 1 holds 22, and 1 + 4 is 5, which leaves 5 after dividing by 7. Slot 5 is free.

if you chose another

  • Slot 2 already holds 15. 8's step is 4, so from slot 1 it moves to slot 5.
  • Slot 1 is 8's home, but 22 already holds it.
  • That walks one slot on each time, 1, 2, 3, as linear probing does. 8's step is 4.

new numbersthe test page's numbers