Wednesday, June 18, 2008

Brute-Force-String Matching

Brute-Force-String Matching (T, P) :


The above Function finds the position of the first character of the pattern P in T if the pattern is present in T, otherwise it returns – 1.
Step 1 Initialization, loop
set n  length [T]
set m  length [P]
for i  0 to n-m
set i  0
while (j < m and P [j] = T [i + j] )
set j  j + 1
if (j = m) then
return i
Step 2 Return value at the point of call.
return – 1

No comments: