Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Naive String Matching Algorithm | Computer Science

1,014 views

Published on

In this approach, the pattern is made to slide over text one by one and test for a match. If a match is found while testing, then it returns the starting index number from where the pattern is found in the text and then slides by 1 again to check for subsequent matches of the pattern in the text. Copy the link given below and paste it in new browser window to get more information on Naive String Matching Algorithm:- http://www.transtutors.com/homework-help/computer-science/naive-string-matching-algorithm.aspx

Published in: Education
  • Be the first to comment

Naive String Matching Algorithm | Computer Science

  1. 1.  Pattern slides over text one by one and tests for a match.  When match found return the starting index number from where the pattern is found in the text  Slide by 1 again to check for subsequent matches of the pattern in the text.
  2. 2. Compare 1 to 1. Match is found !!! Slide the pattern by one then 3 would be compared with 1. No match found!!! Again the pattern will slide by one until a continuous match is found. Now the comparison would be as follows: Match is found !!! String search will return index number 2.
  3. 3. Naïve string matching algorithm Pseudocode: { n = length(text); m = length(patter,); limit = n-m; j = 0, k = 0; array_Shift[]; for(i = 0; i <= limit; i++) { j = 0; k = i; for(j = 0; j <= m AND str[k] == pat[j]; j++) k++; if(j >= m) Add i to array_Shift; } return array_Shift; }
  4. 4. Hey Friends, This was just a summary on Naive String Matching AlgorithmNaive String Matching Algorithm. For more detailed information on this topic, please type the link given below or copy it from the description of this PPT and open it in a new browser window. http://www.transtutors.com/homework-help/computer-science/naive-string- matching-algorithm.aspx

×