KMP prefix table

前端 未结 7 1061
说谎
说谎 2020-12-02 07:58

I am reading about KMP for string matching.
It needs a preprocessing of the pattern by building a prefix table.
For example for the string ababaca

7条回答
  •  青春惊慌失措
    2020-12-02 08:26

    string text = "ababbabbababbababbabb"; static int arr[30];

    int i = 1;
    while (i < text.length())
    {
        int j = 0;
        int value = 0;
        while (((i + j) < text.length()) && (text[j] == text[i + j]))
            val[i + j] = ++value, j++;
        i += j + 1;
    }
    

    required output stored in val[]

提交回复
热议问题