Aec Last
Aec Last
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int M = strlen(pat);
int N = strlen(txt);
// create lps[] that will hold the longest prefix suffix values for pattern
computeLPSArray(pat, M, lps);
while (i < N) {
if (pat[j] == txt[i]) {
j++;
i++;
if (j == M) {
j = lps[j - 1];
if (j != 0)
j = lps[j - 1];
else
i = i + 1;
int i;
i = 1;
while (i < M) {
if (pat[i] == pat[len]) {
len++;
lps[i] = len;
i++;
if (len != 0) {
} else // if (len == 0)
lps[i] = 0;
i++;
int main() {
KMPSearch(pat, txt);
return 0;
OUTPUT:
2)RK ALGORITHM
#include<stdio.h>
#include<string.h>
#define d 256
*/
void search(char *pat, char *txt, int q)
int M = strlen(pat);
int N = strlen(txt);
int i, j;
int h = 1;
h = (h*d)%q;
p = (d*p + pat[i])%q;
t = (d*t + txt[i])%q;
// If the hash values match then only check for characters on by one
if ( p == t )
{
if (txt[i+j] != pat[j])
break;
// Calculate hash value for next window of text: Remove leading digit,
if ( i < N-M )
if(t < 0)
t = (t + q);
int main()
return 0;
}
OUTPUT: Pattern found at index 0