Question discussion

In the Knuth–Morris–Pratt (KMP) algorithm, the prefix (failure) function π[i] is the length of the longest proper prefix of the pattern tha…

2512Medium DSSSB TGT Computer Science 0 replies 1 views
0

In the Knuth–Morris–Pratt (KMP) algorithm, the prefix (failure) function π[i] is the length of the longest proper prefix of the pattern that is also a suffix of its first i characters. For the pattern ababaca, the sum π[1] + π[2] + … + π[7] is

  • A7
  • B6
  • C5
  • D8
Correct answer: A

Explanation

The values of π for a, ab, aba, abab, ababa, ababac and ababaca are 0, 0, 1, 2, 3, 0 and 1, and their sum is 7.

Discussion 0

Nobody has replied yet. Start the discussion!