Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codertcet111/def2ce59b95343364162751b74be68e7 to your computer and use it in GitHub Desktop.
Save codertcet111/def2ce59b95343364162751b74be68e7 to your computer and use it in GitHub Desktop.
Function Naive (T[0....n], P[0.....m])
{
//This function is to find pattern P in the string T
//Inputs are the two string T and P
//Output will be the index of the matched position of T string
for (i = 0, j = 0; to i <= n - m) do
{
if (T[i] == P[j]){
temp_i = i
while(pattern P matching with Text){
i++;
j++;
if j reaches m-1{
pattern matched, return the 'i - m' value as the starting of the matched index in T string
{
} come out of while loop, no match occurs
Now set i = temp_i + 1, j = 0
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment