GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Cuckoo hashing uses two tables of size 7: h1(k) = k mod 7 in T1 and h2(k) = floor(k / 7) mod 7 in T2. To insert x, place it in T1[h1(x)]; if occupied, evict the occupant y, put x there, and try y in T2[h2(y)]; if that is occupied, evict again into T1, alternating. Keys 20, 50, 53, 75, 100, 67, 105, 3, 36, 39 are inserted in order. How many evictions (displacements) happen in total?

  1. A. 9
  2. B. 7
  3. C. 6
  4. D. 10

Correct answer: B. 7

Insert in order, tracking each chain of evictions between the tables; the total number of displacements is 7, and the final tables are T1 = [105, 50, 100, 3, 39, 75, 20] and T2 = [53, None, 67, None, None, 36, None].

More Programming and Data Structures (GATE) questions

Exams that ask this topic