ImageVerifierCode 换一换
格式:PPT , 页数:22 ,大小:203KB ,
资源ID:7281983      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-7281983.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(算法设计与分析20BoyMoore.ppt)为本站会员(lxhqcj)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

算法设计与分析20BoyMoore.ppt

1、String Matching II,Algorithm : Design & Analysis 20,In the last class,Simple String Matching KMP Flowchart Construction Jump at Fail KMP Scan,String Matching II,Boyer-Moores heuristics Skipping unnecessary comparison Combining fail match knowledge into jump Horspool Algorithm Boyer-Moore Algorithm,S

2、kipping over Characters in Text,Longer pattern cantains more information about impossible positions in the text. For example: if we know that the pattern doesnt contain a specific character. It doesnt make the best use of the information by examining characters one by one forward in the text.,An Exa

3、mple,If you wish to understand others you must ,must,must,must,must,Checking the characters in P, in reverse order,must,must,must,must,must,must,must,must,The copy of the P begins at t38. Matching is achieved in 18 comparisons,just passed by,match,mismatch,Distance of Jumping Forward,With the knowle

4、dge of P, the distance of jumping forward for the pointer of T is determined by the character itself, independent of the location in T.,p1 A A pm,p1 A A ps pm,current j,new j,Rightmost A, at location pk,charJumpA = m-k,m-k,t1 tj=A tr tn,next scan,Computing the Jump: Algorithm,Input: Pattern string P

5、; m, the length of P; alphabet size alpha=| Output: Array charJump, indexed 0, alpha-1, storing the jumping offsets for each char in alphabet.,void computeJumps(char P, int m, int alpha, int charJumpchar ch;int k;for (ch=0; chalpha; ch+)charJumpch=m; /For all char no in P, jump by mfor (k=1; km; k+)

6、charJumppk=m-k;,The increasing order of k ensure that for duplicating symbols in P, the jump is computed according to the rightmost,(|+m),Scan by CharJump: Horspools Algorithm,int horspoolScan(char P, char T, int m, int charjump)int j=m-1, k, match=-1;while (endText(T,j) = = false) /up to n loopsk=0

7、;while (km and Pm-k-1 = = Tj-k)/up to m loopsk+;if (k= = m) match=j-m; break;else j=j+charjumpTj;return match;,So, in the worst case: (mn),Partially Matched Substring,P: b a t s a n d c a t sT: d a t s ,matched suffix,Current j charJumpd=4,New j Move only 1 char,Remember the matched suffix, we can g

8、et a better jump,P: b a t s a n d c a t sT: d a t s ,New j Move 7 chars,And cat will be over ats, dismatch expected,scan backward,New cycle of scanning,Basic Idea,T: the text,tj,mismatch,matched,matched suffix,Forward to Match the Suffix,p1 pk pk+1 pm,t1 tj tj+1 tn,Matched suffix,Dismatch,Substring

9、same as the matched suffix occurs in P,p1 pr pr+1 pr+m-k pm,p1 pk pk+1 pm,t1 tj tj+1 tn,Old j,New j,slidek,matchJumpk,Partial Match for the Suffix,p1 pk pk+1 pm,t1 tj tj+1 tn,Matched suffix,Dismatch,No entire substring same as the matched suffix occurs in P,p1 pq pm,p1 pk pk+1 pm,t1 tj tj+1 tn,Old j

10、,New j,slidek,matchJumpk,May be empty,matchjump and slide,p1 pr pr+1 pr+m-k pm,p1 pk pk+1 pm,t1 tj tj+1 tn,Old j,New j,slidek,matchJumpk,slidek: the distance P slides forward after dismatch at pk, with m-k chars matched to the rightmatchjumpk: the distance j, the pointer of P, jumps, that is: matchj

11、umpk=slidek+m-k,Length of the frame is m-k,Determining the slide,Let r(rk) be the largest index, such that pr+1 starts a largest substring matching the matched suffix of P, and prpk, then slidek=k-rIf the r not found, the longest prefix of P, of length q, matching the matched suffix of P will be lin

12、ed up. Then slidek=m-q.,pr=pk is senseless since pk is a mismatch,Computing matchJump: Example,P = “ w o w w o w ”,matchJump6=1,Direction of computing,w o w w o w,t1 tj ,Matched is empty,w o w w o w,matchJump5=3,w o w w o w,t1 tj w ,Matched is 1,w o w w o w,Slide6=1 (m-k)=0,pk,pk,Slide5=5-3=2 (m-k)=

13、1,Computing matchJump: Example,P = “ w o w w o w ”,matchJump4=7,Direction of computing,w o w w o w,t1 tj o w ,Matched is 2,w o w w o w,matchJump3=6,w o w w o w,t1 tj w o w ,Matched is 3,w o w w o w,Not lined up,=pk,No found, but a prefix of length 1, so, Slide4 = m-1=5,pk,Slide3=3-0=3 (m-k)=3,Comput

14、ing matchJump: Example,P = “ w o w w o w ”,matchJump2=7,Direction of computing,w o w w o w,t1 tj w w o w ,Matched is 4,w o w w o w,matchJump1=8,w o w w o w,t1 tj o w w o w ,Matched is 5,w o w w o w,No found, but a prefix of length 3, so, Slide2 = m-3=3,No found, but a prefix of length 3, so, Slide1

15、= m-3=3,Finding r by Recursion,P,p1,pk,pk+1,pk+2,ps,sufxk+1=s,ps+1,Case 1: pk+1=pssufxk=sufxk+1-1,Case 2: pk+1 ps,recursively,Computing the slides: the Algorithm,for (k=1; km; k+) matchjumpk=m+1; sufxm=m+1;for (k=m-1; k0; k-)s=sufixk+1while (sm)if (pk+1= = ps) break;matchjumps = min (matchjumps, s-(

16、k+1);s = sufxs;sufxk=s-1;,initialized as impossible values,Remember: slidek=k-r here: k is s, and r is k+1,Computing the matchjump: Whole Procedure,void computeMatchjumps(char P, int m, int matchjump)int k,r,s,low,shift;int sufx = new intm+1low=1; shift=sufx0;while (shiftm)for (k=low; kshift; k+)mat

17、chjumpk = min(matchjumpk, shift);low=shift+1; shift=sufxshift;for (k=1; km; k+)matchjumpk+=(m-k);return,computing slides for sufix matched shorter prefix,turn into matchjump by adding m-k,Boyer-Moore Scan Algorithm,int boyerMooreScan(char P, char T, int charjump, int matchjump)int match, j, k;match=-1;j=m; k=m; / first comparison locationwhile (endText(T,j) =false)if (k1)match = j+1 /successbreak;if (tj = = pk ) j-; k-;elsej+=max(charjumptj, matchjumpk);k=m;return match;,scan from right to left,take the better of the two heuristics,Home Assignment,pp.508- 11.16 11.19 11.20 11.25,

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报