Sub-character lookup KMP algorithm-substring self-matching index table

Source: Internet
Author: User

     Public Static int[] Kmptable (Char[] seq) {        int[] tbl =New int[Seq.length]; tbl[0] = 1;  for(inti = 1; i < seq.length; i++) {//substring at the beginning            intj = Tbl[i-1];//start with an already calculated indexL1: for(; J <= I; j + +) {                 for(intk = 0; J + k <= i; k++) {                    if(Seq[j + K] = = Seq[k] && j + k = =i) { BreakL1;//Exact Match}Else if(Seq[j + K]! = seq[k] && k >= 1)//substring internal self-matchingJ + =Tbl[k-1]; }} Tbl[i]=J; }        returntbl; }

public static int[] kmptable (char[] seq) {
int[] tbl = new Int[seq.length];
Tbl[0] = 1;
for (int i = 1; i < seq.length; i++) {//substring at the very beginning
Int J = tbl[i-1];//starts from an already calculated index
L1:for (; J <= I; j + +) {
for (int k = 0; j + k <= i; k++) {
if (Seq[j + K] = = Seq[k] && j + k = = i) {
Break l1;//Exact Match
} else if (Seq[j + K]! = seq[k] && k >= 1)//substring internal self-matching
J + = Tbl[k-1];
}
}
Tbl[i] = j;
}
return TBL;
}

Sub-character lookup KMP algorithm-substring self-matching index table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.