GATE Computer ScienceHardGATE CS (PYQ pattern)
Rabin–Karp searches for P = 26 in T = 3141592653589793 using base 10 and modulus 11 on 2-digit windows. How many spurious hits (hash equal but the window is different from P) occur?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: A. 3
26 mod 11 = 4. Windows with value ≡ 4 (mod 11) are 15, 59, 92 and 26; only the last equals P, so 3 are spurious hits. Each spurious hit costs an extra O(m) character comparison.
More Algorithms questions
- Keys 10, 20, 30, …, 100 are inserted in this order into an empty hash table of size 10 with h(k) = k mod 10 and quadratic probing (h(k) +…
- A hash table of size 13 uses double hashing: the probe sequence is (k mod 13 + i·(1 + (k mod 11))) mod 13. Keys 19, 27, 36, 10, 25, 40, 53…
- For the array [8, 3, 10, 1, 7, 5, 12, 2, 9, 4, 6], let X be the number of exchanges bubble sort performs and Y the minimum number of swaps…
- A queue is implemented by two stacks (enqueue pushes onto IN; dequeue pops from OUT, first moving all elements of IN to OUT if OUT is…
- Keys 15, 9, 12, 4, 18, 7, 3, 10, 21, 6 are inserted one by one into an empty binary min-heap (array representation, standard sift-up)…
- Floyd's Build-Heap performs at most height(v) exchanges while sifting down node v, so its exchanges are bounded by H = Σ height(v) over…