KEMBAR78
Naive String Matching Algorithm | Computer Science | PPT
 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.
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.
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;
}
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

Naive String Matching Algorithm | Computer Science

  • 2.
     Pattern slidesover 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.
  • 4.
    Compare 1 to1. 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.
  • 6.
    Naïve string matchingalgorithm 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; }
  • 7.
    Hey Friends, This wasjust 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