kmp 为一个图 而深入认识 ,用输出来说话

http://www.cnblogs.com/titer1/archive/2012/04/01/2429413.html 

图 来自v_july_v 博客图

 

2012年4月1日

21:46

clip_image002

 

pattern_index: 0

debug luky target_index: 1

对应 july图中 index =0

pattern_index: 1

debug luky target_index: 2

pattern_index: 2

debug luky target_index: 3

pattern_index: 3

when   overlay ,debug target_index: 3

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 4

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 5

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 6

pattern_index: 0

debug luky target_index: 7

对应 july图中 index =6

pattern_index: 1

debug luky target_index: 8

pattern_index: 2

when   overlay ,debug target_index: 8

pattern_index: 0

debug luky target_index: 9

对应 july图中 index =8,

图中没有标识

pattern_index: 1

when   overlay ,debug target_index: 9

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 10

pattern_index: 0

debug luky target_index: 11

对应 july图中 index =10

pattern_index: 1

when   overlay ,debug target_index: 11

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 12

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 13

pattern_index: 0

debug luky target_index: 14

对应 july图中 index =13

pattern_index: 1

debug luky target_index: 15

pattern_index: 2

debug luky target_index: 16

pattern_index: 3

debug luky target_index: 17

pattern_index: 4

when   overlay ,debug target_index: 17

pattern_index: 1

这里 发现问题 不一致的bug 作者给出序

  程序中的

string src="annbcdanacadsannannabnna";

string pattern=                         "annacanna"

;

实际是:

string src="annbcdanacadsanannacanna"

;就是故意让最后的结尾满足了pattern..

debug luky target_index: 18

pattern_index: 2

debug luky target_index: 19

pattern_index: 3

debug luky target_index: 20

 

pattern_index: 4

when   overlay ,debug target_index: 20

pattern_index: 1

when   overlay ,debug target_index: 20

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 21

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 22

pattern_index: 0

when   pattern_index ==0 ,debug target_index: 23

pattern_index: 0

debug luky target_index: 24

-1

 

 

 

 

作者的勘误:

 

另一作者saturnman发现,在上述KMP匹配过程图中,index=8和index=11处画错了。还有,anaven也早已发现,index=3处也画错了。非常感谢。但图已无法修改,见谅。

我和 zy的讨论

clip_image001

zy

index = 0 时 annb 算到 k = -1; 所以应该向后移4-(-1+1)次

66

简言之,index=3应该 pass,

 

为什么这个在我的输出力没有检测 出来??

zy

index = 6 时  ana 算到 k = 0 所以应该向后移 3-0+1)次

66

就是说 index=8不应该被 pass

第8 11 处的错找不到。。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值