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 14, 70, 21, 63 and 42, all with home 0. How many probes do the five puts make in all?

the answer, and why

the answer is A

14 takes slot 0, 1 probe. Each of the others has its own step, 1, 2, 4, 3, and finds slot 0 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 14 finds slot 0 taken.
  • That counts 2 probes for 14 too, but its home is free.

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 31 and 45, then 94. Which slot does 94 go in?

the answer, and why

the answer is D

31 takes slot 3. 45, home 3 and step 1, takes slot 4. 94 has home 3 and step 5. Slot 3 holds 31, and 3 + 5 is 8, which leaves 1 after dividing by 7. Slot 1 is free.

if you chose another

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

new numbersthe test page's numbers