Skip to content

Hash table that grows

storing

Level 2 of 3

Also called Resizing a hash table, Rehashing and Dynamic hash table.

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

choose one

question 1

A table that grows starts with 2 empty slots and puts in 48, 95, 43, 62 and 22. How many numbers are moved in all?

the answer, and why

the answer is A

The slots double before the 2nd, 3rd and 5th numbers, moving 1, 2 and 4. 1 + 2 + 4 is 7.

if you chose another

  • That counts only the last doubling, before the 5th number.
  • That counts one move a number, but the 1st and 4th move nothing and the 5th moves 4.
  • That counts up to the 9th number, which moves 8 more.

new numbersthe test page's numbers

question 2

A table that grows starts with 2 empty slots and puts in 66, 62, then 28. Which slot does 28 go in?

the answer, and why

the answer is A

Before 28, 3 numbers in 4 slots would be more than half, so the slots double to 8. 28 leaves 4 when divided by 8, and slot 4 is empty.

if you chose another

  • Slot 6 holds 62. 28's home in 8 slots is 4.
  • Slot 2 holds 66. 28's home in 8 slots is 4.
  • That is the next slot after 62, but 28's own home is empty.

new numbersthe test page's numbers

question 3

A table that grows starts with 2 empty slots and puts in 64, 25, 87, 79 and 71. How many slots does it end with?

the answer, and why

the answer is C

5 numbers in 8 slots is more than half, so before the 5th the slots double from 8 to 16.

if you chose another

  • 8 slots hold 4 numbers at half full; the 5th doubles them.
  • The slots only double, 2, 4, 8, 16, so 10 never comes.
  • 16 slots hold 8 numbers at half full, so 32 comes only at the 9th.

new numbersthe test page's numbers