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 66, 10, 3, 94 and 87, all with home 3. How many probes do the five puts make in all?

the answer, and why

the answer is A

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

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 32 and 60, then 53. Which slot does 53 go in?

the answer, and why

the answer is C

32 takes slot 4. 60, home 4 and step 1, takes slot 5. 53 has home 4 and step 4. Slot 4 holds 32, and 4 + 4 is 8, which leaves 1 after dividing by 7. Slot 1 is free.

if you chose another

  • Slot 5 already holds 60. 53's step is 4, so from slot 4 it moves to slot 1.
  • Slot 4 is 53's home, but 32 already holds it.
  • That walks one slot on each time, 4, 5, 6, as linear probing does. 53's step is 4.

new numbersthe test page's numbers