3. The Brute Force algorithm compares the pattern to
the text, one character at a time, until unmatching
characters are found :
What search engine do, exactly solve string matching
problem, you type keyword in search engine search
box you search entire document in webpage is string matching
The algorithm can be designed to stop on either the
first occurrence of the pattern, or upon reaching the
end of the text.
4. She sells sea shell on the sea shore
If pattern is shell
shell
shell
shell
shell
Shell ….
shell
In first search 3 comparison are matched and from second only one
comparison Matched and finally we matched 5 comparison are
Matched.
We may do up to m comparison, because of pattern is length m
5. string matching takes two in put
(T[0….n-1], P[0….m-1])
for i ← 0 to n-m do
j ← 0
while j<m and P[j]= T[ i + j] do
j ← j+1
If j=m return i
Return -1
In every position of given text, do the next element of
the array match the m elements of the pattern (in the
same order).
//m <= n