File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load diff This file was deleted.
Original file line number Diff line number Diff line change 88
99我们刚才说过了 BF 算法,但是 BF 算法是有缺陷的,比如我们下面这种情况
1010
11- ![ BF第一次 ] ( https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/BF第一次.2qo0876qvs80. png )
11+ ![ 在这里插入图片描述 ] ( https://img-blog.csdnimg.cn/20210401200433751. png )
1212
1313
1414
1818
1919我们可以跳过其中某些步骤,直接到下面这个步骤。那我们是依据什么原则呢?
2020
21- ![ BM3 ] ( https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/BM3.7iamevkxf0g0 .png )
21+ ![ 在这里插入图片描述 ] ( https://img-blog.csdnimg.cn/20210401200635476 .png )
2222
2323### 坏字符规则
2424
@@ -32,7 +32,7 @@ BM 算法是从后往前进行比较,此时我们发现比较的第一个字
3232
3333那我们在模式串中找到坏字符该怎么办呢?
3434
35- ![ 含有坏字符 ] ( https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/含有坏字符.10z8yxka8z8g .png )
35+ ![ 在这里插入图片描述 ] ( https://img-blog.csdnimg.cn/20210401200838199 .png )
3636
3737此时我们的坏字符为 f ,我们在模式串中,查找发现含有坏字符 f,我们则需要移动模式串 T ,将模式串中的 f 和坏字符对齐。见下图。
3838
@@ -74,15 +74,15 @@ BM 算法是从后往前进行比较,此时我们发现比较的第一个字
7474
7575好后缀其实也很容易理解,我们之前说过 BM 算法是从右往左进行比较,下面我们来看下面这个例子。
7676
77- ![ 好后缀1 ] ( https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/好后缀1.4j88yw6hecu0 .png )
77+ ![ 在这里插入图片描述 ] ( https://img-blog.csdnimg.cn/20210401201215799 .png )
7878
7979这里如果我们按照坏字符进行移动是不合理的,这时我们可以使用好后缀规则,那么什么是好后缀呢?
8080
8181BM 算法是从右往左进行比较,发现坏字符的时候此时 cac 已经匹配成功,在红色阴影处发现坏字符。此时已经匹配成功的 cac 则为我们的好后缀,此时我们拿它在模式串中查找,如果找到了另一个和好后缀相匹配的串,那我们就将另一个和** 好后缀相匹配** 的串 ,滑到和好后缀对齐的位置。
8282
8383是不是感觉有点拗口,没关系,我们看下图,红色代表坏字符,绿色代表好后缀
8484
85- ![ ] ( https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/好后缀对其.5wf80nidao80 .png )
85+ ![ 在这里插入图片描述 ] ( https://img-blog.csdnimg.cn/20210401201254453 .png )
8686
8787![ ] ( https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/好后缀中间.7b6m6ki25l00.png )
8888
You can’t perform that action at this time.
0 commit comments