| STRING ALGORITHMS | ||||||||
| Algorithm for KMP string matcher | ||||||||
KMP string matching first preprocesses the given pattern P to compute FailureFunction. Then the output of the FailureFunction is used to skip some of the invalid comparisons. Note that the preprocessing is done once for each pattern. Since in general the size of the pattern to be searched is relatively small, it takes far less time than the string matching process. |
||||||||
KMP stringMatch (T, P) |
||||||||
KMP algorithm runs in optimal time O(m+n) time. |
||||||||
| Prev | ||||||||