GATE Computer ScienceHardGATE CS (PYQ pattern)
For the pattern P = abcabdabcabcabd, the KMP failure (prefix) function π[i] is the length of the longest proper prefix of P[0..i] that is also a suffix of it. What is the sum π[0] + π[1] + … + π[14]?
- A. 33
- B. 38
- C. 36
- D. 41
Correct answer: C. 36
π = [0, 0, 0, 1, 2, 0, 1, 2, 3, 4, 5, 3, 4, 5, 6]. At index 5 (d) the border is lost (0), it rebuilds through abcab (5) at index 10, and at index 11 the match abcab is followed by d, so the algorithm falls back to the border ab (length 2) and extends it with c to 3. The entries sum to 36.
More Algorithms questions
- Boyer–Moore–Horspool searches for P = abcab in T = abcabdabcabcabcabxab (20 characters). The window is compared right to left; after every…
- 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…