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 25, 11, 41, 73 and 90. How many numbers are moved in all?

the answer, and why

the answer is C

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 14, 25, then 45. Which slot does 45 go in?

the answer, and why

the answer is D

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

if you chose another

  • Slot 1 holds 25. 45's home in 8 slots is 5.
  • Slot 6 holds 14. 45's home in 8 slots is 5.
  • That is the next slot after 25, but 45'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 44, 24, 29, 38 and 83. How many slots does it end with?

the answer, and why

the answer is D

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