Can this word search algorithm be made faster?
- by Ashwin Singh
Problem: Find a match of word S in text T
Given: S and T are part of spoken and written English.
Example: Match 'Math' in 'I love Mathematics'
NOTE: Ignore CASES.
My algorithm:
STEP 1) Convert S, T to char[]
STEP 2) for i=0, i < T.length , i++
STEP 3) for j=S.length-1, j>0 , j--
STEP 3 is the magic, instead of going about matching M,A,T,H, this matches M, H, T and finally A. This helps in eliminating a lot of possible partial matches. For example, if I go sequentially like M A as in Boyer Moore's method ... it can match Matter, Mass, Matchstick etc. using M _ _ H will bring down size of partial matches.
STEP 4) if S[j]!=T[i] -> break;
else if j==i -> PRINT MATCH