Data Structures & AlgorithmsVery hardGATE CS

For the pattern P = "abaabaabaabab", the KMP failure (prefix) function pi[i] is the length of the longest proper prefix of P[0..i] that is also its suffix. What is the sum of pi[0..12]?

  1. A. 53
  2. B. 45
  3. C. 48
  4. D. 50

Correct answer: C. 48

The array is [0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 2], whose sum is 48.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic