Question

In the Knuth-Morris-Pratt (KM

  • M {         if (pat[i] == pat[len]) {             len++;             lps[i] = len;             i++;         } else { // (pat[i] != pat[len])             if (len != 0) {                 _________; // Line to complete             } else { // if (len == 0)                 lps[i] = 0;                 i++;             }         }     } }
  • P algorithm, the Longest Proper Prefix Suffix (LP
  • S array lps[] is crucial. When pat[i] and pat[len] match, len is incremented and lps[i] is set to len. What happens when pat[i] and pat[len] *do not* match and len is not 0? void computeLPSArray(char* pat, int M, int* lps) {     int len = 0;     lps[0] = 0;     int i = 1;     while (i <
A len = 0;
B len = lps[len - 1];
C i++;
D lps[i] = len;
E len = len - 1;
Practice Next

Hey! Ask a query