GATE Computer ScienceVery hardGATE CSE · NIELIT

The KMP failure (prefix) function π[i] of pattern P = "abaabaabaabab" gives, for each prefix P[0..i], the length of its longest proper prefix that is also a suffix. What is the sum π[0] + π[1] + … + π[12]?

  1. A. 51
  2. B. 48
  3. C. 46
  4. D. 54

Correct answer: B. 48

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

More Programming and Data Structures (GATE) questions

Exams that ask this topic