Skip to content
Official PYQ · 2014

GATE CS 2014 Set 1 Q40 — Arrays, Stacks and Queues

Explain with AI

Consider a hash table with 99 slots. The hash function is h(k)=kmod  9h(k)= k \mod 9. The collisions are resolved by chaining. The following 99 keys are inserted in the order: 5,28,19,15,20,33,12,17,105, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are

Choose one option
View worked solution

Answer: A

To find the maximum, minimum, and average chain lengths, we map each key to its corresponding slot in the hash table of size 99 using the hash function h(k)=k mod 9h(k) = k \bmod 9.

Let's compute the slot index for each key in the order of insertion:

  • h(5)=5 mod 9=5h(5) = 5 \bmod 9 = 5
  • h(28)=28 mod 9=1h(28) = 28 \bmod 9 = 1
  • h(19)=19 mod 9=1h(19) = 19 \bmod 9 = 1
  • h(15)=15 mod 9=6h(15) = 15 \bmod 9 = 6
  • h(20)=20 mod 9=2h(20) = 20 \bmod 9 = 2
  • h(33)=33 mod 9=6h(33) = 33 \bmod 9 = 6
  • h(12)=12 mod 9=3h(12) = 12 \bmod 9 = 3
  • h(17)=17 mod 9=8h(17) = 17 \bmod 9 = 8
  • h(10)=10 mod 9=1h(10) = 10 \bmod 9 = 1

Now, we group the keys into their respective slots (chains):

  • Slot 0: Empty (Chain length = 00)
  • Slot 1: 28→19→1028 \to 19 \to 10 (Chain length = 33)
  • Slot 2: 2020 (Chain length = 11)
  • Slot 3: 1212 (Chain length = 11)
  • Slot 4: Empty (Chain length = 00)
  • Slot 5: 55 (Chain length = 11)
  • Slot 6: 15→3315 \to 33 (Chain length = 22)
  • Slot 7: Empty (Chain length = 00)
  • Slot 8: 1717 (Chain length = 11)

From the slot distribution, we can determine the required metrics:

  1. Maximum chain length: The longest chain is at Slot 1, which has a length of 3\mathbf{3}.
  2. Minimum chain length: Slots 0, 4, and 7 are empty, so the minimum chain length is 0\mathbf{0}.
  3. Average chain length: Average=Total number of keysTotal number of slots=99=1\text{Average} = \frac{\text{Total number of keys}}{\text{Total number of slots}} = \frac{9}{9} = \mathbf{1}

Thus, the maximum, minimum, and average chain lengths are 3,0,3, 0, and 11 respectively.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions