for at its beginningwe repeat this process until we find match of in or the index for reaches nthe length of (indicating that we did not find the pattern pintcode fragment the kmp pattern matching algorithm the main part of the kmp algorithm is the while loopwhich performs comparison between character in and character in each iteration depending upon the outcome of this comparisonthe algorithm either moves on to the next characters in and pconsults the failure function for new candidate character in por starts over with the next index in the correctness of this algorithm follows from the definition of the failure function any comparisons that are skipped are actually unnecessaryfor the failure function guarantees that all the ignored comparisons are redundant--they would involve comparing the same matching characters over again figure an illustration of the kmp pattern matching algorithm the failure function for this pattern is given in example the algorithm performs character comparisonswhich are indicated with numerical labels