KMP Algorithm

1. What is the time complexity of Naive-String-Searching Algorithm? (N = length of string in which pattern is searched , M = length of pattern to be searched)
Explanation

Explanation

Explanation

Explanation

Explanation

Explanation

Explanation

Explanation

2. What will be the output of the following code (cpp snippet) ?
string s = “kmpalgo”;
int n = s.size();
string s2 = “algo”;
int m = s2.size();
Int i=0;
int flag = 0;
while(i{
int j = i;
int k = 0;
int flag1 = 0;
while(j{
if(s[j] == s2[k])
{ j++;k++;}
else
{ flag1 = 1;break;}
}
if(flag1==0)
{ flag =1;break)
i++;
}
cout << flag << endl;

Explanation

Explanation

Explanation

Explanation

Explanation

Explanation