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 32, 4, 67 and 26, in that order. How many probes do the four puts make in all?

the answer, and why

the answer is C

32, 4 and 67 have home 4; 26 has home 5. 32 takes slot 4, 1 probe. 4 walks to slot 5, 2 probes. 67 walks slots 4 and 5 to slot 6, 3 probes. 26 finds slot 5 taken by 4, then slot 6 by 67, 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 26 as 1 probe, as if its home were free, but 4 took slot 5 on its walk.
  • That leaves out 26's put, which makes 3 probes.

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 4, 53 and 95, then 67. Which slot does 67 go in?

the answer, and why

the answer is B

All four have home 4. 4 takes slot 4, 53 slot 5, 95 slot 6, so 67 walks 4, 5 and 6 to slot 0.

if you chose another

  • Slot 4 is 67's home, but 4 already holds it.
  • That stops at the first slot after its home, two too early; slot 5 holds 53.
  • That walks one slot too far; slot 0 is free.

new numbersthe test page's numbers