Skip to content

Hash table with open addressing

storing

Level 2 of 3

Also called Linear probing.

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 open addressing's own run on the numbers shown.

choose one

question 1

An empty table of 7 slots puts in 99, 36, 15 and 44, in that order. How many probes do the four puts make in all?

the answer, and why

the answer is B

99, 36 and 15 have home 1; 44 has home 2. 99 takes slot 1, 1 probe. 36 walks to slot 2, 2 probes. 15 walks slots 1 and 2 to slot 3, 3 probes. 44 finds slot 2 taken by 36, then slot 3 by 15, and takes slot 4, 3 probes. That is 9.

if you chose another

  • That counts 1 probe a put, as if every home were free.
  • That counts 44 as 1 probe, as if its home were free, but 36 took slot 2 on its walk.
  • That leaves out 44's put, which makes 3 probes.

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 93, 79 and 9, then 30. Which slot does 30 go in?

the answer, and why

the answer is A

All four have home 2. 93 takes slot 2, 79 slot 3, 9 slot 4, so 30 walks 2, 3 and 4 to slot 5.

if you chose another

  • Slot 2 is 30's home, but 93 already holds it.
  • That stops at the first slot after its home, two too early; slot 3 holds 79.
  • That walks one slot too far; slot 5 is free.

new numbersthe test page's numbers