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?
- A. 9
- B. 7
- C. 6
- 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].
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Keys 19, 36, 5, 21, 4, 26, 14, 17, 25, 12, 40, 33 are inserted into a chained hash table with 7 buckets, h(k) = k mod 7, each new key…
- A max-heap is built from [90, 80, 70, 60, 50, 40, 30, 20, 10, 15, 25, 35, 45, 55, 65] by bottom-up heapify. Then the key at index 14 is…
- Two stacks (values and operators) evaluate 12-(3+4(5-2))/53+8/(1+1) with all operators left-associative and integer division truncating…
- How many index pairs i < j satisfy a[i] + a[j] == 10 in the array {3, 8, 5, 2, 7, 4, 6, 1, 9, 5, 3, 7}?
- unsigned x = 0x369; / binary 11 0110 1001 / unsigned s = 0, c = 0; while (x) { unsigned t = x & -x; c++; s += t c; x -= t; } What is s…
- int a[3][4] = {{3,1,4,1},{5,9,2,6},{5,3,5,8}}; int t = 0; for (int j = 0; j < 4; j++) for (int i = 0; i < 3; i++) t += ((a + i) + j) (j +…