String Match 字符串匹配

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

GCAGAGAG
KMP Skip Search Algorithm
This algorithm considers skip search and KMP search
First it uses the Skip Search algorithm to align T and P.
T = ACTACATATAGGACTACGTACCAGCATTACTACGTT P = ACTACGT
Exact String Match
Skip Search Algorithm
1. Preprocessing
Text string T=GCATCGCAGAGAGTATACAGTACG 01234567
Pattern string P= GCAGAGAG
a bucket saving position information
a b T = aaaababbababbbbbbaabababababba 0 1 2 3 4 5 6 7 b a b ababbaba a b百度文库b a No bbb in P Match! [5,0] [2] [4,1] [3]
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Alpha Skip Search Algorithm
1. Preprocessing
Pattern = a b a b b a b a
a
b a
b
b
Build a Trie!
a
[5,0]
b
b
a
[3]
[2] [4,1]
Alpha Skip Search Algorithm
2. Search Phase
such that: w is a suffix of u or u is a suffix of w; w is a prefix of v of v is a prefix of w.
In other words, w occurs at both sides of the cut between u and v with a possible overflow on either side
Definitions Period: A strictly positive integer p is called a period of x if x[i] =x[i+ p],
whenever both sides are defined.
Local Period:
Local Period: i.e. the length of w
Critical Factorization:
Search Phase:
Proof:
String Matching on Ordered Alphabets
Reference:
http://www-igm.univ-mlv.fr/~lecroq/string/ Two-way String Matching, MAXIME CROCHEMORE AND DOMINIQUE PERRIN String-matching on ordered alphabets, Maxime Crochemore, Theoretical Computer Science 92 (1992) 33-47 Skip Search algorithm, Advisor: Prof. R. C. T. Lee, Speaker: Z. H. Pan, Lecture Notes in Computer Science, Vol. 1448, 1998, pp. 55-64
Skip Search Algorithm #
2. Search Phase
GCATCGCAGAGAGTATACAGTACG
critical
GCAGAGAG
GCAGAGAG
mismatch
mismatch exact match
GCAGAGAG
Then we check T[15]=T. Since there is no “T” in the pattern, we check T[23]=G. Then we shift pattern to align T[16…23].
T = aaaababbababbbbbbaabababababba ababbaba
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Match!
Two Way Algorithm
T = aaaababbababbbbbbaabababababba ababbaba
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Match!
No aab in P
0 1 2 3 4 5 6
ACTACGT
0
1 0
2 1
3 2
4 3
5 6 4
(kmp’s shift) (skip’s shift)
ACTACGT
5 6
Four Cases
kmpStart < skipStart < wall then a shift according to the shift table of Morris-Pratt is applied. This gives a new value for kmpStart. We have to compare again skipStart and kmpStart; skipStart < kmpStart then a shift according to the skip algorithm is applied which gives a new value for skipStart, and we have to compare againskipStart and kmpStart; kmpStart < wall < skipStart then another attempt can be performed with start = skipStart. skipStart = kmpStart then another attempt can be performed with start = skipStart;
相关文档
最新文档