KMP算法解决思路

KMP算法
我看了一下KMP算法,感觉非常难理解,几乎看不懂,你们是怎么理解KMP算法的?

 #include <stdio.h>
 #include <stdlib.h>
 
 const char *kmp_search(const char *text, const char *pattern)
 {
     int *T;
     int i, j;
     const char *result = NULL;
 
     if (pattern[0] == '\0')
       return text;
 
     /* Construct the lookup table */
     T = malloc((strlen(pattern)+1) * sizeof *T);
     T[0] = -1;
     for (i=0; pattern[i] != '\0'; i++) {
         T[i+1] = T[i] + 1;
         while (T[i+1] > 0 && pattern[i] != pattern[T[i+1]-1])
           T[i+1] = T[T[i+1]-1] + 1;
     }
 
     /* Perform the search */
     for (i=j=0; text[i] != '\0'; ) {
         if (j < 0 || text[i] == pattern[j]) {
             ++i, ++j;
             if (pattern[j] == '\0') {
                 result = text+i-j;
                 break;
             }
         }
         else j = T[j];
     }
 
     free(T);
     return result;
 }

------解决思路----------------------
kmp理解确实比较难,楼主可以去试着看看ac自动机。然后就懂kmp了。