Typedef struct string { Int length; Char str[1000]; }string; H E L L O \0 Linked List Representation:
Typedef struct string { Char symbol; Struct string *next; }string; H O \0 L L E Brute force Algorithm Knuth morris pratt Algorithm Rabin Karp Algorithm check for a match between the first characters of the pattern with the first character of the string . If they dont match we move forward the second character of the string.
int brutestringsearch(char *s,char *p) { int i,j,k,m,n; n=strlen(s); m=strlen(p); for(i=0;i<=(n-m);i++) { j=0; k=I; while((s[k]==p[j])&&(j<m)) { K++; } if(j==m) return I; } return(-1) } Complexity is o(mn). It can be very useful Doesnt require pre-processing of the text Doesnt require additional space Can be quite effective for short texts and patterns It can be ineffective If we search more than once the text Its slow
searches for occurrences of a pattern" P within a main "text string" S by employing the observation that when a mismatch occurs, the word itself embodies sufficient information to determine where the next match could begin. Eg: P = "ABCDABD" and S = "ABC ABCDAB ABCDABCDABDE
Iteration 1: m=0,i=0
M:01234567890123456789012 S:ABC ABCDAB ABCDABCDABDE P: ABCDABD i: 0123456 Iteration 2: m = 4 and i = 0. m: 01234567890123456789012 S: ABC ABCDAB ABCDABCDABDE P: ABCDABD i: 0123456 Iteration 3: m = 8, i = 2. m: 01234567890123456789012 S: ABC ABCDAB ABCDABCDABDE P: ABCDABD i: 0123456 Iteration 4: m = 11, i = 0.
m: 01234567890123456789012 S: ABC ABCDAB ABCDABCDABDE p: ABCDABD i: 0123456 Iteration 5: m = 15, i = 0.