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 62, 34, 48 and 28, in that order. How many probes do the four puts make in all?

the answer, and why

the answer is B

62, 34 and 48 have home 6; 28 has home 0. 62 takes slot 6, 1 probe. 34 walks to slot 0, 2 probes. 48 walks slots 6 and 0 to slot 1, 3 probes. 28 finds slot 0 taken by 34, then slot 1 by 48, and takes slot 2, 3 probes. That is 9.

if you chose another

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

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 52, 24 and 17, then 87. Which slot does 87 go in?

the answer, and why

the answer is D

All four have home 3. 52 takes slot 3, 24 slot 4, 17 slot 5, so 87 walks 3, 4 and 5 to slot 6.

if you chose another

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

new numbersthe test page's numbers