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

the answer, and why

the answer is A

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

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 1, 85 and 78, then 8. Which slot does 8 go in?

the answer, and why

the answer is C

All four have home 1. 1 takes slot 1, 85 slot 2, 78 slot 3, so 8 walks 1, 2 and 3 to slot 4.

if you chose another

  • Slot 1 is 8's home, but 1 already holds it.
  • That stops at the first slot after its home, two too early; slot 2 holds 85.
  • That walks one slot too far; slot 4 is free.

new numbersthe test page's numbers