GATE Computer ScienceVery hardGATE CSE

The KMP prefix (failure) function π[i] is the length of the longest proper prefix of P[0..i] that is also a suffix of it. For P = abababcabababd (14 characters), what is the sum of π[0] to π[13]?

  1. A. 31
  2. B. 28
  3. C. 34
  4. D. 37

Correct answer: A. 31

π = [0, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 0], which sums to 31.

More Algorithms questions

Exams that ask this topic