GATE Computer ScienceHardGATE CS (PYQ pattern)
A hash table of size 13 uses double hashing with h1(k) = k mod 13, h2(k) = 1 + (k mod 11) and probe sequence (h1 + i·h2) mod 13. The keys 18, 41, 22, 44, 59, 32 are inserted in that order, then 31. In which slot does 31 land?
- A. 2
- B. 5
- C. 7
- D. 12
Correct answer: D. 12
After the first six keys slots 5, 2, 9, 6, 7 and 4 are filled. For 31: h1 = 5 (filled) and h2 = 1 + 9 = 10, so i = 1 gives slot 2 (filled) and i = 2 gives (5 + 20) mod 13 = 12, which is free.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A dynamic array starts with capacity 1. Whenever an append finds it full, a new array of double the capacity is allocated and all current…
- In an AVL tree a single node has height 0. What is the minimum number of nodes in an AVL tree of height 6?
- int f(int n) { static int c = 0; c += n; if (n > 0) f(n - 1); return c; } int main() { int x = f(4); int y = f(2); printf("%d", x + y); }…
- Assume a 32-bit unsigned int. What does the following program print? #include <stdio.h> int main() { unsigned s = 0; for (unsigned i = 1…
- Assume uint16t is a 16-bit unsigned type, int is 32 bits and the characters are ASCII. What is printed? uint16t h = 7; for (const char p =…
- int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int mul(int a, int b) { return a b; } int main() { int…