While applying Boyer–Moore string search algorithm to the string :
SSIMPLE EXAMPLE
with a pattern:
EXAMPLE
the algorithm flows as :
SSIMPLE EXAMPLE ---------------------(1)
EXAMPLE
SSIMPLE EXAMPLE ----------------------------(2)
EXAMPLE
SSIMPLE EXAMPLE ----------------------------------(3)
EXAMPLE
but when applying the same algorithm to the same string :
SSIMPLE EXAMPLE
but with a slightly different pattern : (replacing the first E with a T)
TXAMPLE
the algorithm flows as :
SSIMPLE EXAMPLE ------------------- (1)
TXAMPLE
SSIMPLE EXAMPLE ----------------------(2)
TXAMPLE
SSIMPLE EXAMPLE ---------------------------(3)
TXAMPLE
From the first example :
In the second step,E is under E
and in the second example :
In the second step,T is not under E but under a space
why is that ? What difference does the alphabets T and E make in the word TXAMPLE and EXAMPLE respectively ?
In EXAMPLE, the first and last characters are the same, so if you match the last character, then you know that the string has an E at that position. So when you try and shift EXAMPLE along, you have to assume that the E in that position matches the first E in example.
in TXAMPLE, the last character occurs only at the end of the string, so if you match the last character, then you can shift the string along so far that the next attempted match does not overlap at all with the first one, because E doesn’t match anywhere except at the end of the string.