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?
- A. 4
- B. 2
- C. 3
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the sum of the Z-function values Z[i] for i = 1 to n-1 of the string aaabaaab (Z[i] is the length of the longest common prefix of…
- How many palindromic substrings (counted by position, so repeated letters at different positions count separately) does the string…
- What is the minimum number of characters that must be inserted anywhere in the string abcbd to make it a palindrome?
- How many distinct non-empty substrings does the string ababa have?
- What is the length of the longest substring of abcabcbbxyzw that contains no repeated character?
- What is the length of the shortest substring of aabdecbcaeb that contains every character of abc (with multiplicity: at least one of each…