1.Horspool
2.KMP
3.Boyer Moore
4.Sunday algorithm
串匹配中,核心是匹配过程中的步长如何确定。
设这个pattern的size为m,text的size为n,如下开始套讨论:
1.Horspool算法处理时,会先生成一张表,表里记录应该移动多少。总是根据text串的字符c和pattern中的最后一个相对应的字符,来确定如何移动。
目标串 text
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
模式串 pattern
TCCTATTCTT
(1)产生shift table
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
Horspol
A C T
5 2 1
start.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
1.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
2.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTC TT
3.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
4.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
5.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
6.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTC TT
7.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
8.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
9.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
10.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
11.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
12.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
13.
TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
TCCTATTCTT
BM
KMP
pi 0 1 2 3 4 5 6 7
-1 0 0 1 2 3 0 1
d = q-pi[q]
start.
bacbabababacaca
ababaca
1.q=1
bacbabababacaca
ababaca