GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Boyer–Moore–Horspool searches for P = abcab in T = abcabdabcabcabcabxab (20 characters). The window is compared right to left; after every window (match or mismatch) it shifts by shift[c], where c is the text character under the last pattern position, shift[c] = 4 − (last index of c in P[0..3]) and shift[c] = 5 if c does not occur in P[0..3]. How many windows (alignments) are examined?
- A. 16
- B. 4
- C. 7
- D. 6
Correct answer: D. 6
shift[a] = 1, shift[b] = 3, shift[c] = 2, others 5. Windows start at 0 (match, last char b → +3), 3 (mismatch, b → +3), 6 (match, +3), 9 (match, +3), 12 (match, last char b → +3), 15 (window abxab: mismatch, b → +3 → 18 > 15, stop). That is 6 windows, of which 4 are matches; the naive method would try all 16.
More Algorithms questions
- 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…
- 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)…