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
2. 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.
3.
4. 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.
5.
6. 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;
}
7. 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