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 \mod…

A hash table of length 10 uses open addressing with hash function h(k)=kmod  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}

Which one of the following choices gives a possible order in which the key values could have been inserted in the table?

  1. A
    46,42,34,52,23,3346, 42, 34, 52, 23, 33
  2. B
    34,42,23,52,33,4634, 42, 23, 52, 33, 46
  3. C
    46,34,42,23,52,3346, 34, 42, 23, 52, 33
    Correct answer
  4. D
    42,46,33,23,34,5242, 46, 33, 23, 34, 52

Answer

(C) 46 , 34 , 42 , 23 , 52 , 33 46, 34, 42, 23, 52, 33 46 , 34 , 42 , 23 , 52 , 33

Approach

Use the given hash function and linear probing: each key first tries slot k mod 10; if occupied, it moves to the next slot cyclically until an empty slot is found. Simulate each listed insertion order and compare the final table with the given table: 42 at 2, 23 at 3, 34 at 4, 52 at 5, 46 at 6, 33 at 7.

Only the insertion order 46, 34, 42, 23, 52, 33 produces the exact final hash table after linear probing. The other orders place at least one key in a different slot.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.