Data Structures & AlgorithmsModerateGATE CS · TCS NQT

What is the value of the prefix-function (KMP failure function) at the last position of the string aabaaab?

  1. A. 4
  2. B. 2
  3. C. 3
  4. D. 5

Correct answer: C. 3

The prefix function is the length of the longest proper prefix that is also a suffix ending at that index. Using the failure link (not restarting from zero) gives the reliable value.

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

Exams that ask this topic