Answer
Pattern = an
m$\ \ \ \ $$\ \ \ \ $ = 2.
The pattern has 2 characters.
Text$\ \ \ \ $ = A man and a woman
n$\ \ \ \ $$\ \ \ \ $ = 17.
The text has 17 characters.
k$\ \ \ \ $i$\ \ \ \ \ $Mismatch$\ \ \ $ Operation
1$\ \ \ \ $1$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ \ $ Compare $P_{1}$, the “a”, to $T_{1}$, the “A”. No match.
$\ \ \ \ $$\ \ \ \ \ \ \ $ Yes$\ \ \ \ $$\ \ \ \ $$\ \ \ \ \ $End of the check for a match at position 1 of the text.
2$\ \ \ \ $1$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ Compare $P_{1}$, the “a”, to $T_{2}$, the blank. No match.
$\ \ \ \ $$\ \ \ \ \ \ \ $ Yes$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $End of the check for a match at position 2 of the text.
3$\ \ \ \ $1$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ Compare $P_{1}$, the “a”, to $T_{3}$, the “m”. No match.
$\ \ \ \ $$\ \ \ \ \ \ \ $ Yes$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $End of the check for a match at position 3 of the text.
4$\ \ \ \ $1$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ Compare $P_{1}$, the “a”, to $T_{4}$, the “a”. Match.
4$\ \ \ \ $2$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ Compare $P_{2}$, the “n”, to $T_{5}$, the “n”. Match.
4$\ \ \ \ $3$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ $i (3)$ is greater than $m (2)$, so we exit the loop.
Output: There is a match at position 4
In a similar way, the program will produce the following two additional lines of output:
There is a match at position 7
There is a match at position 16
Work Step by Step
Pattern = an
m$\ \ \ \ $$\ \ \ \ $ = 2.
The pattern has 2 characters.
Text$\ \ \ \ $ = A man and a woman
n$\ \ \ \ $$\ \ \ \ $ = 17.
The text has 17 characters.
k$\ \ \ \ $i$\ \ \ \ \ $Mismatch$\ \ \ $ Operation
1$\ \ \ \ $1$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ \ $ Compare $P_{1}$, the “a”, to $T_{1}$, the “A”. No match.
$\ \ \ \ $$\ \ \ \ \ \ \ $ Yes$\ \ \ \ $$\ \ \ \ $$\ \ \ \ \ $End of the check for a match at position 1 of the text.
2$\ \ \ \ $1$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ Compare $P_{1}$, the “a”, to $T_{2}$, the blank. No match.
$\ \ \ \ $$\ \ \ \ \ \ \ $ Yes$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $End of the check for a match at position 2 of the text.
3$\ \ \ \ $1$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ Compare $P_{1}$, the “a”, to $T_{3}$, the “m”. No match.
$\ \ \ \ $$\ \ \ \ \ \ \ $ Yes$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $End of the check for a match at position 3 of the text.
4$\ \ \ \ $1$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ Compare $P_{1}$, the “a”, to $T_{4}$, the “a”. Match.
4$\ \ \ \ $2$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ Compare $P_{2}$, the “n”, to $T_{5}$, the “n”. Match.
4$\ \ \ \ $3$\ \ \ \ $No$\ \ \ \ $$\ \ \ \ $$\ \ \ \ $ $i (3)$ is greater than $m (2)$, so we exit the loop.
Output: There is a match at position 4
In a similar way, the program will produce the following two additional lines of output:
There is a match at position 7
There is a match at position 16