RB Matcher String Matching Technique
RB Matcher String Matching Technique
Vol:2 2008-06-27
from text for all the possible shifts which are from s=0 to nm(where n denotes the length of text and m denotes the length
of P). So according to this two number n1 and n2 can only be
equal if
REM (n1/q) = REM (n2/q) [1]
After division we will be having three cases :Case 1:
Successful hit: - In this case if REM (n1) = REM(n2) and also
characters of n1 matches with characters of n2.
Case 2:
Spurious hit: - In this case REM (n1) = REM (n2) but
characters of n1 are not equal to characters of n2.
Case 3:
If REM (n1) is not equal to REM (n2), then no need to
compare n1 and n2.
ExFor a given text T, pattern P and prime number q
so to find out this pattern from the given text T we will take
equal number of characters from text as in pattern and divide
these characters with predefined number q and also divide the
pattern with the same predefined number q. Now compare
their remainders to decide whether to compare the text with
pattern or not.
Rem (Text) =234567/11=3
Rem (Pattern) =667888/11=1
As both the remainders are not equal so there is no need to
compare text with pattern. Now move on to next set of
characters from text and repeat the procedure. [1]. If
remainders match then only we compare the part of text to the
pattern otherwise there is no need to perform the comparison.
We will maintain three variables Successful Hit, Spurious Hit
and Unsuccessful Hit.
Rabin Karp Matcher Algorithm
Rabin_Matcher (T,P,d,q)
{
n =Length (T)
m= Length (P)
t0=0
p=0
h=dm-1mod q
995
For i=1 to m
{ p = (dp+P[i]) mod q
t0 =(d t0 + T[i] ) mod q
}
For s =0 to n-m
{ If ts=p
{ then
{ if P[1.m]=T[s+1.s+m]
then print pattern matches at shift s
}
}
if s<= n-m
ts+1= (d(ts-h*T[s+1]) + T[s+1+m] ) mod q
}
}[1]
B. Algorithms
The modified algorithm is as follows:RB_ Matcher (T,P,d,q)
{
n =Length (T)
m= Length (P)
t0=0
p=0
Q=0
pq=0
h=dm-1mod q
For i=1 to m
{
p = (dp+P[i]) mod q
t0 =(d t0 + T[i] ) mod q
}
pq= P[1..m] DIV q
For s =0 to n-m
{
Q=T{s+1.s+ m] DIV q
If (ts = p and Q = pq)
{
996
(Q denotes Quotient)
In this algorithm comparison of pattern and Text will
always lead to successful hits.
C. Test Cases
We will some study test cases for the modified algorithms
complexity.
TABLE I FOR MODIFIED RABIN KARP MATCHER (CONSTANT TEXT LENGTH)
S No
997
Length of
text (n)
Length of
pattern
(m)
100
10
VALUE
OF q
2
3
5
7
11
13
Complexity
(n-m+1)
91
91
91
91
91
91
100
100
100
15
20
50
17
19
23
2
3
5
7
11
13
17
19
23
2
3
5
7
11
13
17
19
23
2
3
5
7
11
13
17
19
23
91
91
91
86
86
86
86
86
86
86
86
86
81
81
81
81
81
81
81
81
81
49
49
49
49
49
49
49
49
49
Length
of
text
(n)
100
Length
of pattern
(m)
10
200
10
300
10
VALU
E OF q
Complexity
(n-m+1)
2
3
5
7
11
13
17
19
23
2
3
5
7
11
13
17
19
23
2
3
5
91
91
91
91
91
91
91
91
91
191
191
191
191
191
191
191
191
191
291
291
291
10
291
291
291
291
291
291
391
391
391
391
391
391
391
391
391
IV. CONCLUSION
With the above, we concluded that any numeric pattern can
be found out from the given Text T by following Modified
RB matcher in an effective & efficient way. We also invite
other Research Scholars to work on same and find out some
better way to find out string from the given text.T.
REFERENCES
[1]
[2]
[3]
[4]
S
No
400
7
11
13
17
19
23
2
3
5
7
11
13
17
19
23
998