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 63, 7, 91, 35 and 49, all with home 0. How many probes do the five puts make in all?

the answer, and why

the answer is B

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

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 96 and 40, then 89. Which slot does 89 go in?

the answer, and why

the answer is A

96 takes slot 5. 40, home 5 and step 1, takes slot 6. 89 has home 5 and step 5. Slot 5 holds 96, and 5 + 5 is 10, which leaves 3 after dividing by 7. Slot 3 is free.

if you chose another

  • Slot 6 already holds 40. 89's step is 5, so from slot 5 it moves to slot 3.
  • Slot 5 is 89's home, but 96 already holds it.
  • That walks one slot on each time, 5, 6, 0, as linear probing does. 89's step is 5.

new numbersthe test page's numbers