Download presentation
Presentation is loading. Please wait.
1
1 Two Way Algorithm Advisor: Prof. R. C. T. Lee Speaker: C. C. Yen Two-way string-matching Journal of the ACM 38(3):651-675, 1991 Crochemore M., Perrin D.
2
2 In 2003,Rytter proposed a constant space and linear time string matching algorithm To achieving the good constant space, this algorithm avoids the preprocessing function table of the KMP algorithm Before introducing this algorithm, we shall define some characteristic of the strings
3
3 The Property of Maximal Suffix Consider a string P. Let P = uv where v = MaxSuf(P). The property of the maximal suffix of a string is: If u is non-empty, no suffix of u will be equal to a prefix of v. Example : Consider a pattern = ababadada. Let P = uv =ababa.dada No suffix of u is equal to a prefix of v.
4
4 Short Maximal Suffix If a maximal suffix of a string x satisfies, we say that this maximal suffix of x is a short maximal suffix of x. Example : Consider a string x = abcdda,dda is a maximal suffix of x and. Hence we say that dda is a short maximal suffix of x
5
5 Short Prefixes Lemma Let the decomposition of P = uv, where v is the maximal suffix of P and v is also a short maximal suffix. Suppose that we start to match v with T at position i, a part of v is matched and a mismatch occurs at the j +1-th position on v. Then we can shift P safely by j + 1 positions without missing any occurrence of P in T. ii+j+1 v mismatch u u v T: P: jj j
6
6 Why do we have to use short maximal suffix? Suppose V’ is very long, then we move pattern which is incorrect. i j vu T: P: i j v’ j vu T: P: i j j+1
7
7 In the following, we will introduce the basic rule of the Two Way Matching algorithm with short maximal pattern strings The basic rules are given in the next slides.
8
8 Basic rule of the Two-Way algorithm with short maximal 1.Let the decomposition of P =uv, where v is the maximal suffix of P and v is also a short maximal suffix. 2.We then find where v appears in T from left to right. Assume the comparison starts at position i. When a mismatch occurs at v[j + 1], we shift v with j + 1 characters and start next comparison at P[1] with T[i + j + 1]. 3.When the part of v has be found in T, we scan the part of u from right to left. If a mismatch occurs when scanning u, we shift P with Period(P) 4.If we find both the parts of v and u in T, we report an occurrence of P in T. We then shift v with Period(P)
9
9 Full Example T=adadadaddadababadada P=u.v = ababa.dada Pababadada 123456789 123456789101112131415161718 Tadadadaddadabadada
10
10 T=adadadaddadababadada P=u.v = ababa.dada 1234 Pababadada 123456789 123456789101112131415161718 Tadadadaddadabadada Shift 4 steps Pababadada 123456789
11
11 T=adadadaddadababadada P=u.v = ababa.dada 1234 Pababadada 123456789 123456789101112131415161718 Tadadadaddadabadada Shift 1 steps Pababadada 123456789
12
12 T=adadadaddadababadada P=u.v = ababa.dada 1234 Pababadada 123456789 12345678910111213141516171819202122 Tadadadaddadadababadada Shift Preiod(P) = 8 steps Pababadada 123456789 Rule 1 again!
13
13 T=adadadaddadababadada P=u.v = ababa.dada 1234 Pababadada 123456789 12345678910111213141516171819202122 Tadadadaddadadababadada Shift Preiod(P) = 8 steps Pababadada 123456789 Match!!
14
14 References BRESLAUER, D., 1996, Saving comparisons in the Crochemore-Perrin string matching algorithm, Theoretical Computer Science 158(1-2):177-192. CROCHEMORE, M., 1997. Off-line serial exact string searching, in Pattern Matching Algorithms, ed. A. Apostolico and Z. Galil, Chapter 1, pp 1-53, Oxford University Press. CROCHEMORE M., PERRIN D., 1991, Two-way string-matching, Journal of the ACM 38(3):651-675. CROCHEMORE, M., RYTTER, W., 1994, Text Algorithms, Oxford University Press.
15
15 Thanks for your attention
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.