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

the answer, and why

the answer is A

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

if you chose another

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

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 14, 63 and 7, then 42. Which slot does 42 go in?

the answer, and why

the answer is B

All four have home 0. 14 takes slot 0, 63 slot 1, 7 slot 2, so 42 walks 0, 1 and 2 to slot 3.

if you chose another

  • Slot 0 is 42's home, but 14 already holds it.
  • That stops at the first slot after its home, two too early; slot 1 holds 63.
  • That walks one slot too far; slot 3 is free.

new numbersthe test page's numbers