Professional Documents
Culture Documents
Adviser: R. C. T. Lee
Speaker: C. W. Cheng
National Chi Nan University
Problem Definition
Input: a text string T with length n and a pattern
string P with length m.
Output: all occurrences of P in T.
Definition
n : The length of T.
m : The length of P.
Introduction
simplification of the Boyer-Moore algorithm.
uses only the bad-character shift.
easy to implement.
very fast in practice
uses Rule 2-2: 1-Suffix Rule
x
P
x
i
1
Shift
P
1
y
f
z
i
Shift
y
f
P
1
z
i
y
f
bmBC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
tbmBC[A]=1, shift=1
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
AGCAGAC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
tbmBC[G]=2, shift=2
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
AGCAGAC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
AGCAGAC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
tbmBC[C]=4, shift=4
AGCAGAC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
AGCAGAC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
AGCAGAC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
tbmBC[C]=4, shift=4
AGCAGAC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
AGCAGAC
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
tbmBC[T]=7, shift=7
Example
Text string
T=GCGAGCAGACGTGCGAGTACG
Pattern string
P=AGCAGAC
tbmBC
AGCAGAC
Time complexity
preprocessing phase in O(m+ ) time and O()
space complexity, is the number of alphabets
in pattern.
searching phase in O(mn) time complexity.
Reference
[KMP77] Fast pattern matching in strings, D. E. Knuth, J. H. Morris, Jr and V. B. Pratt, SIAM J. Computing, 6,
1977, pp. 323350.
[BM77] A fast string search algorithm, R. S. Boyer and J. S. Moore, Comm. ACM, 20, 1977, pp. 762772.
[S90] A very fast substring search algorithm, D. M. Sunday, Comm. ACM, 33, 1990, pp. 132142.
[RR89] The Rand MH Message Handling system: Users Manual (UCIVersion), M. T. Rose and J. L. Romine,
University of California, Irvine, 1989.
[S82] A comparison of three string matching algorithms, G. De V. Smith, SoftwarePractice and Experience,12,
1982, pp. 5766.
[HS91] Fast string searching, HUME A. and SUNDAY D.M. , Software - Practice & Experience 21(11), 1991, pp.
1221-1248.
[S94] String Searching Algorithms , Stephen, G.A., World Scientific, 1994.
[ZT87] On improving the average case of the Boyer-Moore string matching algorithm, ZHU, R.F. and
TAKAOKA, T., Journal of Information Processing 10(3) , 1987, pp. 173-177 .
[R92] Tuning the Boyer-Moore-Horspool string searching algorithm, RAITA T., Software - Practice &
Experience,
22(10) , 1992, pp. 879-884.
[S94] On tuning the Boyer-Moore-Horspool string searching algorithms, SMITH, P.D., Software - Practice &
Experience, 24(4) , 1994, pp. 435-436.
[BR92] Average running time of the Boyer-Moore-Horspool algorithm, BAEZA-YATES, R.A., RGNIER, M.,
Theoretical Computer Science 92(1) , 1992, pp. 19-31.
[H80] Practical fast searching in strings, HORSPOOL R.N., Software - Practice & Experience, 10(6) , 1980, pp.
501-506.
[L95] Experimental results on string matching algorithms, LECROQ, T., Software - Practice & Experience 25(7) ,
1995, pp. 727-765.