[ACE] String matching 1
Definition of string matching problem informal: given a text(sequence of characters) T of length n, and a pattern P(sequence of characters) of length m, determine if P occurs in T Naive string matching algorithm NaiveStringMatch(T, P) for(s = 0; s < T.length - P.length; s++) j = 1; while(T[s+j] == P[j] and j <= P.length) j++; if(j == P.length+1) return s; return -1; note that the array started at index 1 instead of 0 note that s is a shift(not an array index) and so counts from 0 not 1 note also that if T.length < P.length, the for loop is skipped, and we return -1 immediately Naive algorithm NaiveStringMatch moves the pattern along the text string, until it finds a shift(offset) for which the characters in the pattern are equal to the characters in the next The for loop considers each possible shift explicitly, start with a 0 shift The while loop and conditional determines whether the current shift i...