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 18, 88, 95 and 12, in that order. How many probes do the four puts make in all?

the answer, and why

the answer is C

18, 88 and 95 have home 4; 12 has home 5. 18 takes slot 4, 1 probe. 88 walks to slot 5, 2 probes. 95 walks slots 4 and 5 to slot 6, 3 probes. 12 finds slot 5 taken by 88, then slot 6 by 95, and takes slot 0, 3 probes. That is 9.

if you chose another

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

new numbersthe test page's numbers

question 2

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

the answer, and why

the answer is B

All four have home 5. 40 takes slot 5, 89 slot 6, 33 slot 0, so 82 walks 5, 6 and 0 to slot 1.

if you chose another

  • Slot 5 is 82's home, but 40 already holds it.
  • That stops at the first slot after its home, two too early; slot 6 holds 89.
  • That walks one slot too far; slot 1 is free.

new numbersthe test page's numbers