下载此文档

算法导论-ch32 string matching.ppt


文档分类:IT计算机 | 页数:约40页 举报非法文档有奖
1/40
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/40 下载此文档
文档列表 文档介绍
Ch32StringMatchingIntroductionNaïveAlgorithmRabin-KarpAlgorithm StringMatchingusingFiniteAutomataKnuth-Morris-Pratt(KMP)AlgorithmLiteratureCormen,Leiserson,Rivest,“IntroductiontoAlgorithms”,chapter32,stringmatching,TheMITPress,2001,906-?urrencesofapatterninagiventext(orbodyoftext)ManyapplicationsWhileusingeditor/wordprocessor/browserLoginname&municationsDNAsequenceanalysis2HistoryofStringSearchThebruteforcealgorithm:puterhistoryre-inventedmanytimes,monKnuth&Prattinventedabetteronein1970published1976as“Knuth-Morris-Pratt”Boyer&Moorefoundabetteronebefore1976Published1977Karp&Rabinfounda“better”onein1980Published19873String-MatchingProblemThetextisinanarrayT[1..n]oflengthnThepatternisinanarrayP[1..m]oflengthmElementsofTandParecharactersfromafinitealphabet.,={0,1}or={a,b,…,z}UsuallyTandParecalledstringsofcharacters4String-MatchingProblem…urswithshiftsintextTif: 0≤s≤n-mandT[(s+1)..(s+m)]=P[1..m]urswithshiftsinT,thensisavalidshift,otherwisesisaninvalidshiftString-matchingproblem:findingallvalidshiftsforagivenTandP5Example1abcabaabcabacabaatextTpatternPs=3shifts=3isavalidshift(n=13,m=4and0≤s≤n-mholds)12345678910**********Example2abcabaabcabaaabaatextTpatternPs=3abaaabaas=912345678910**********NaïveString-MatchingAlgorithmInput:TextstringsT[1..n]andP[1..m]Result:AllvalidshiftsdisplayedNAÏVE-STRING-MATCHER(T,P) n←length[T] m←length[P] fors←0ton-m ifP[1..m]=T[(s+1)..(s+m)] print“urswithshift”s8ExampleP=“abxyabxz”andT=“xabxyabxyabxz”xazxbaybxyabxTzxbabxyaPabxyabxzazbxyabxzxabxyabzxbabxyazxbaabxyzxbayabx9Worst-parisonsforeachshiftintheworstcaseTherearen-m+1shiftsSo,theworst-caserunningtimeisΘ((n-m+1)m)Naïvemethodisinefficientbecauseinformationfromashiftisnotusedagain10

算法导论-ch32 string matching 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数40
  • 收藏数0 收藏
  • 顶次数0
  • 上传人cai.li.bin
  • 文件大小535 KB
  • 时间2019-06-06