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 86, 51, 65 and 59, in that order. How many probes do the four puts make in all?

the answer, and why

the answer is A

86, 51 and 65 have home 2; 59 has home 3. 86 takes slot 2, 1 probe. 51 walks to slot 3, 2 probes. 65 walks slots 2 and 3 to slot 4, 3 probes. 59 finds slot 3 taken by 51, then slot 4 by 65, and takes slot 5, 3 probes. That is 9.

if you chose another

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

new numbersthe test page's numbers

question 2

An empty table of 7 slots puts in 50, 78 and 15, then 29. Which slot does 29 go in?

the answer, and why

the answer is B

All four have home 1. 50 takes slot 1, 78 slot 2, 15 slot 3, so 29 walks 1, 2 and 3 to slot 4.

if you chose another

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

new numbersthe test page's numbers