GATE Computer ScienceHardGATE CS (PYQ pattern)
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 appended at the end of its chain. Counting one comparison per key examined, what is the average cost of a successful search (each stored key equally likely) and of an unsuccessful search (each bucket equally likely, the whole chain scanned)?
- A. 29/12 and 19/7
- B. 29/12 and 12/7
- C. 17/12 and 12/7
- D. 29/7 and 12/7
Correct answer: B. 29/12 and 12/7
Chains: 0: 21, 14; 1: 36; 3: 17; 4: 4, 25; 5: 19, 5, 26, 12, 40, 33; buckets 2 and 6 are empty. Successful: a key at position p costs p, so the total is 3 + 1 + 1 + 3 + 21 = 29 over 12 keys. Unsuccessful: scanning a whole chain costs its length; the lengths add up to 12 over 7 buckets, 12/7. Counting a final NULL check as an extra comparison would give 19/7.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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 +…
- A queue is a circular array that starts with capacity 4 and doubles (copying every element) when an enqueue finds it full; dequeues never…