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 35, 84, 77 and 50, in that order. How many probes do the four puts make in all?

the answer, and why

the answer is A

35, 84 and 77 have home 0; 50 has home 1. 35 takes slot 0, 1 probe. 84 walks to slot 1, 2 probes. 77 walks slots 0 and 1 to slot 2, 3 probes. 50 finds slot 1 taken by 84, then slot 2 by 77, and takes slot 3, 3 probes. That is 9.

if you chose another

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

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 3, 52 and 31, then 73. Which slot does 73 go in?

the answer, and why

the answer is A

All four have home 3. 3 takes slot 3, 52 slot 4, 31 slot 5, so 73 walks 3, 4 and 5 to slot 6.

if you chose another

  • Slot 3 is 73's home, but 3 already holds it.
  • That stops at the first slot after its home, two too early; slot 4 holds 52.
  • That walks one slot too far; slot 6 is free.

new numbersthe test page's numbers