Skip to content

Hash table with chaining

storing

Level 2 of 3

Also called Separate chaining.

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 chaining's own run on the numbers shown.

choose one

question 1

An empty table of 5 buckets puts in 26, 7, 32, 22 and 91, in that order. How many looks do the five puts make in all?

the answer, and why

the answer is D

Each put looks at every number already in its bucket, the remainder after dividing by 5: put by put, 0 + 0 + 1 + 2 + 1, 4 in all.

if you chose another

  • That counts every number before each put, as if all shared one bucket.
  • That counts only 22's 2 looks, but other puts meet numbers too.
  • That counts 1 look for each put into a bucket holding numbers, but 22 meets 2.

new numbersthe test page's numbers

question 2

Which five numbers, put into an empty table in this order, cost the fewest looks?

the answer, and why

the answer is D

Putting in 59, 40, 8, 56, 28 takes 1 look, the fewest of the four: the fewer numbers share a bucket, the fewer looks.

if you chose another

  • That list takes 3 looks, more than 1.
  • That list takes 3 looks, more than 1.
  • That list takes 2 looks, more than 1.

new numbersthe test page's numbers

question 3

An empty table puts in 4, 29 and 24, takes 29 out, then puts in 89. How many looks do the five operations make?

the answer, and why

the answer is A

4 finds bucket 4 empty, 0. 29 meets 4, 1. 24 meets 4 and 29, 2. Taking 29 out meets 4, then finds 29, 2. 89 meets 4 and 24, 2. That is 7.

if you chose another

  • That counts the take as a walk of the whole bucket, but it stops at 29.
  • That leaves out the take's 2 looks.
  • That counts the take as 1 look, but it meets 4 before it finds 29.

new numbersthe test page's numbers