Skip to content
Official PYQ · 2010

GATE CS 2010 Q53 — Arrays, Stacks and Queues

Explain with AI

A hash table of length 1010 uses open addressing with hash function h(k)=k mod   10h(k) = k \: \mod \: 10, and linear probing. After inserting 66 values into an empty hash table, the table is shown as below
0124232343455264673389\begin{array}{|l|l|}\hline \text{0} & \text{} \\ \hline \text{1} & \text{} \\ \hline \text{2} & \text{42} \\ \hline \text{3} & \text{23} \\ \hline \text{4} & \text{34} \\ \hline \text{5} & \text{52} \\ \hline \text{6} & \text{46} \\ \hline \text{7} & \text{33} \\ \hline \text{8} & \text{} \\ \hline \text{9} & \text{} \\ \hline \end{array}

How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above?

Choose one option
View worked solution

Answer: C

To find the number of valid insertion sequences, we analyze the dependencies between the keys based on their hash values h(k)=k(mod10)h(k) = k \pmod{10} and their final positions in the table:

  • 42 (h(42)=2h(42) = 2): Placed at index 2. No dependencies.
  • 23 (h(23)=3h(23) = 3): Placed at index 3. No dependencies.
  • 34 (h(34)=4h(34) = 4): Placed at index 4. No dependencies.
  • 46 (h(46)=6h(46) = 6): Placed at index 6. No dependencies.
  • 52 (h(52)=2h(52) = 2): Placed at index 5. For 5252 to probe and land at index 5, indices 2, 3, and 4 must already be occupied. Thus, 42, 23, and 34 must be inserted before 52.
  • 33 (h(33)=3h(33) = 3): Placed at index 7. For 3333 to probe and land at index 7, indices 3, 4, 5, and 6 must already be occupied. Thus, 23, 34, 52, and 46 must be inserted before 33.

Combining these constraints, we get the following partial order (poset) on the 6 keys:

  • 42,23,34≺5242, 23, 34 \prec 52
  • 52,46≺3352, 46 \prec 33

Since all other 5 elements must be inserted before 3333, 3333 must be at the very last position (position 6) of any valid insertion sequence.

For the remaining 5 elements {42,23,34,52,46}\{42, 23, 34, 52, 46\}, the only constraint is that 42,23,42, 23, and 3434 must precede 5252.

  • The total number of permutations of these 5 elements is 5!=1205! = 120.
  • Among the 4 elements {42,23,34,52}\{42, 23, 34, 52\}, 5252 must appear last. The probability of 5252 being the last among these 4 elements in a random permutation is 14\frac{1}{4}.

Therefore, the number of valid insertion sequences is:

5!4=1204=30\frac{5!}{4} = \frac{120}{4} = 30

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

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