Skip to main content

GATE CSE 2010Data Structures › Hashing & Complexity AnalysisVerified

GATE CSE 2010 PYQ: A hash table of length 10 10 10 uses open addressing with hash function h ( k ) = k m o d 10 h(k) = k \:…

A hash table of length 10 uses open addressing with hash function h(k)=k mod   10h(k) = k \: \mod \: 10, and linear probing. After inserting 6 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?

  1. A
    10
  2. B
    20
  3. C
    30
    Correct answer
  4. D
    40

Answer

(C) 30 30 30

Approach

Model the final table as constraints on the insertion order. For 52 to land in slot 5, its home slot 2 plus slots 3 and 4 must already be occupied, so 42, 23, and 34 must precede 52. For 33 to land in slot 7, all of slots 3,4,5,6 must already be occupied, so 23,34,52,46 must precede 33. Count topological orders satisfying these precedence constraints.

Option C (30) is correct. The final table forces 42,23,34 before 52, and 23,34,52,46 before 33. Hence 33 is last. The remaining five keys can be ordered with 42,23,34 before 52, giving 3! + 4! = 6 + 24 = 30 valid insertion sequences.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.