9.9k views
4 votes
Demonstrate what happens when you insert the keys 1,10,9,99,63,18,36,27,54 and 45 into a hash table with collisions resolved by chaining (using a linked-lists every slot). Let the table have 7 slots and let the hash function be h(k)=k%%. You must draw a diagram of the instance of your hash table (after all keys are inserted),

User J Spen
by
8.7k points

1 Answer

2 votes

Final answer:

When using hash tables with chaining to resolve collisions, the keys 1, 10, 9, 99, 63, 18, 36, 27, 54, and 45 are inserted into a hash table with 7 slots. The hash function used is h(k) = k%7. A diagram is provided showing the instance of the hash table after all keys are inserted.

Step-by-step explanation:

When inserting the keys 1, 10, 9, 99, 63, 18, 36, 27, 54, and 45 into a hash table with 7 slots and collisions resolved by chaining, we use the hash function h(k) = k%7.

For each key, we calculate the hash value by taking the remainder when divided by 7:

  • 1 % 7 = 1
  • 10 % 7 = 3
  • 9 % 7 = 2
  • 99 % 7 = 1
  • 63 % 7 = 0
  • 18 % 7 = 4
  • 36 % 7 = 1
  • 27 % 7 = 6
  • 54 % 7 = 5
  • 45 % 7 = 3

Then, we create a linked list for each slot and insert the keys accordingly:

  1. Slot 0: 63
  2. Slot 1: 1 -> 99 -> 36
  3. Slot 2: 9
  4. Slot 3: 10 -> 45
  5. Slot 4: 18
  6. Slot 5: 54
  7. Slot 6: 27

User Steven Jiang
by
7.8k points