GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A hash table starts with 7 slots, uses linear probing with h(k) = k mod size, and after each insertion, if the load factor exceeds 0.7, it grows to 2 * size + 1 and reinserts the existing keys in the old table's slot order (each reinsertion counts probes too). Keys 10, 20, 30, 40, 50, 60, 70, 80 are inserted in order. What is the total number of probes (a probe is a slot examined) and the final table size?
- A. 20 probes, size 15
- B. 18 probes, size 15
- C. 20 probes, size 7
- D. 23 probes, size 31
Correct answer: A. 20 probes, size 15
Rehashing happens when the load factor passes 0.7 (1 time(s)); tracing every insertion and reinsertion gives 20 probes and a final size of 15.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A grid (S start, T target, # blocked, . free) is searched by BFS with 4-directional moves: S.#..... .##.###. ....#... .##.#.#. ...#..#T…
- How many 10-bit unsigned values x (0 to 1023) have no two adjacent 1 bits, where bit 9 and bit 0 also count as adjacent (the bits are…
- unsigned g(unsigned n) { return n ^ (n >> 1); } For which 8-bit n is g(n) == 0xB5? Give n in decimal.
- A routine compresses runs in place: each maximal run of a repeated character c of length L becomes c if L = 1, else c followed by the…
- A 4 x 6 matrix (4 rows, 6 columns) holds 1 to 24 in row-major order. Its elements are visited in an anticlockwise spiral that starts at…
- int a[] = {1,1,2,2,2,3,4,4,5,5,5,5,6}; int w = 2; for (int i = 2; i < 13; i++) if (a[i] != a[w - 2]) a[w++] = a[i]; What is w after the…