180 likes | 868 Views
Raita Algorithm. Tuning the Boyer-Moore-Horspool string searching algorithm , Software - Practice & Experience, 22(10):879-884 T. RAITA Advisor: Prof. R. C. T. Lee Speaker: H. M. Chen. String Matching Problem.
E N D
Raita Algorithm Tuning the Boyer-Moore-Horspool string searching algorithm, Software - Practice & Experience, 22(10):879-884 T. RAITA Advisor: Prof. R. C. T. Lee Speaker: H. M. Chen
String Matching Problem • Given a pattern string P of length m and a text string T of length n, we would like to know whether there exists an occurrence of P in T. Text Pattern
Basic idea • For each position of the search window, we compare its last character(ß) with the last character of the pattern. • If they match, we compare the first character of the pattern with that of the window. If they match , we compare the middle character of the pattern with that of the window. Then, we search the pattern from second character to the end until we either find the pattern or fail on a text character. Forward search ß Text 2 3 1 Pattern
Basic idea • Then, whether there was a match or not, we shift the window according to the next occurrence of the letter ß in the pattern. Text ß Safe shift ß no ß αin this part
If a mismatch or a complete match occurs, the Raita algorithm uses the Horspool Algorithm.
Preprocessing phase raBc table P = p0p1…pm-2pm-1.The value of pm-2is set to 1, the value of p0 is m-1. The value is increase towards to left from pm-2 to p0. We choose the smallest value of each alphabet. The value of other alphabet(*) is set to m. Example : T : P : 7 6 5 4 3 2 1
Example(1/4) A C G * 1 6 2 8 First attempt mismatch Secnod attempt mismatch 2 1
Example(2/4) A C G * 1 6 2 8 Third attempt mismatch 2 1 Fourth attempt 2 3 4 5 6 7 8 1
Example(3/4) A C G * 1 6 2 8 Fifth attempt mismatch Sixth attempt mismatch
Example(4/4) A C G * 1 6 2 8 Seventh attempt mismatch 2 1 The Raita algorithm performs 18 character comparisons on the example.
Time complexity • preprocessing phase in O(m+σ) time and O(σ) space complexity. • searching phase in O(mn) time complexity. (σ is the number of storing characters)
References • RAITA T., 1992, Tuning the Boyer-Moore-Horspool string searching algorithm, Software - Practice & Experience, 22(10):879-884. • SMITH, P.D., 1994, On tuning the Boyer-Moore-Horspool string searching algorithms, Software - Practice & Experience, 24(4):435-436.