南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)串匹配

计算机问题求解一论题4-11 串匹配 2017年5月3日
计算机问题求解 – 论题4-11 - 串匹配 2017年5月3日

问题1: 什么是string-matching problem,直观上?形式上?
string-matching problem

text T a b c a a a b a b a S=3 pattern a a we say that pattern P occurs with shift s in text T (or,equivalently,that pattern P occurs beginning at position s+1 in text T)if 0≤s≤n-m and T5+l.s+m=P[l.m(that is,.ifT5+j】=P[Ujl,for 1jm).If P occurs with shift s in T,then we call s a valid shift;otherwise, we call s an invalid shift.The string-matching problem is the problem of finding all valid shifts with which a given pattern P occurs in a given text T

text T a b a b a a b a b a c S=3 pattern P a b a a Algorithm Preprocessing time Matching time Naive 0 O(n-m+1)m) Rabin-Karp ⊙(m) O(n-m+1)m) Finite automaton O(mΣ) ⊙(n) Knuth-Morris-Pratt ⊙(m) ©(n)

最容易想到的算法 a a a b a a a b c a a a b a a a b S=0 =3 a b a b 问题2: 为什么称它为nave”算法?
最容易想到的算法

NAIVE-STRING-MATCHER(T,P) 1 n T.length 2 m =P.length 3 for s 0 to n-m 4 ifP1..m]==T[s+1..s+m 5 print"Pattern occurs with shift"s 问题3: 为什么在最坏情况下复杂 度是平方级的?

问题4: 你能否说说nave算法 有什么问题,为什么有 可能改进?

最容易想到的算法 a a b a a a b a a b a a a b S=0 5=3 a a b a a a a b 逐位单字符比较 NAIVE-STRING-MATCHER(T,P) 1 n T.length 2 m= P.length 3 for s =0to n-m 4 ifP[1..m==T[s+1..s+m 5 print "Pattern occurs with shift"s
最容易想到的算法

问题5, Rabin-Karp算法的基本 思想是什么? For expository purposes,let us assume that=,1,2..,so that each character is a decimal digit.(In the general case,we can assume that each charac- ter is a digit in radix-d notation,where d)We can then view a string of k consecutive characters as representing a length-k decimal number.The character string 31415 thus corresponds to the decimal number 31,415

Preprocessing 问题6: Rabin-Karp算法是采用“预处理 方式的算法?何为“预处理”,这 个算法预处理的结果是什么? 31415→m0d13→ 7 1234567891011121314151617 1819 2359023141526739921 mod 13 8931101784510117911
Preprocessing
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)NP完全理论初步.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)密码算法.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)代数编码.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)数论基础.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)群同态基本定理与正规子群.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)群初步.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)线性规划.pptx
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)矩阵计算.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)图论的其它专题(平面图与图着色).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)最大流算法.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)图中的匹配与覆盖(图中的匹配与因子分解).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)旅行问题(图旅行).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)图中的连通度和距离.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)多源最短通路算法 All-Pair Shortest Paths.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)单源最短通路算法.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)树.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)图的计算机表示以及遍历.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)图的基本概念.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)B树.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)用于动态等价关系的数据结构.pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)近似算法的基本概念.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)算法问题的形式化描述.pptx
- 《计算机问题求解》课程参考书籍:《算法学——计算精髓》PDF电子版(Algorithmics - The Spirit of Computing,THIRD EDITION,David Harel).pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)为什么计算机能解题.ppt
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)什么样的推理是正确的.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)基本的算法结构.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)常用的证明方法.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)计算思维引导.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)如何将算法告诉计算机.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)数据与数据结构.pptx
- 《计算机问题求解》课程教学资源(阅读材料)Computational Thinking:What and Why?.pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)关系及其基本性质.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)集合及其运算.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)函数.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)有限与无限.pptx
- 《计算机问题求解》课程教学资源(参考教材)Computer Algorithms - Introduction to Design and Analysis.pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)Hashing方法.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)分治法与递归.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)基本数据结构.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)堆与堆排序.pptx