BF algorithm (brute force matching algorithm)

Source: Internet
Author: User

Compares the main string m specified position and the target string s start position, if the same compares the next character of M with the next character of S, if different then the next character of M and the start position of S is compared until each character in S is equal to the contiguous string in m, otherwise it does not match.

C # code--

       Private Static intIndex (stringMintPosstrings) {intM_len =m.length; intS_len =s.length; inti = pos-1; intj =0; if(pos>M_len) {                return-1; }             while(I<m_len && j<S_len) {                if(m[i]==S[j]) {i++; J++; }                Else{J=0; I= I-j +1; }            }            if(j>=S_len) {                returnIS_len; }            Else            {                return 0; }        }//called intres = Index ("ASDFGHJKL",2,"FGHJK"); Console.WriteLine (res);

Complexity of O (m*n)

BF algorithm (brute force matching algorithm)

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.