Data structure-String-Pattern match
来源:互联网 发布:淘宝上的药可以买吗 编辑:程序博客网 时间:2024/05/05 13:55
Pattern matching is a powerful and elegant way of extracitng information from some certain objectives.And it plays a central role in functional programming.
There are two kinds of pattern match.
Brute algorithm:
Time complexity:O(m*n)
KMP algorithm:
Time complexity:O(m+n)
j
1
2
3
4
5
6
7
8
9
10
pattern string
a
b
a
a
b
c
a
c
a
b
next[j]
0
1
1
2
2
3
1
2
1
1
Thinking process(two methods):
1) if j=1 --> next[j]=0
if set is not empty --> next[j]=Max{k|1<k<j,且'p1…pk'='p(j-k+1)…p(j-1)'}
other situation --> 1.
2) if j=x --> compare pattern string of next[x-1] and pattern string of
next[next[x-1]] -->
if the value is same,next[x]=next[x-1]+1;
else,we should continue to compare the pattern string of (j=next[next[x-1]]) and pattern string of (j=x-1).
Pay attention: while j=1,the corresponding pattern string still differs from the pattern string of next[next[x-1]] --> next[x]=0+1=1.
- Data structure-String-Pattern match
- Hash Tables: String Search--Data Structure
- [转]java.lang.String中,match()的用法,即String.match(String pattern)
- pattern match
- match pattern
- Data Structure
- Data structure
- Data Structure
- Data structure
- Data structure
- data structure
- Data Structure
- Data structure
- Data Structure
- Data Structure
- Data Structure
- Data Structure
- Data structure alignmentData structure alignment
- 项目从windows迁移到linux注意事项
- 喷水装置二
- imp导入数据到ORACLE遭遇ORA-12899错误
- 顺序存储栈代码
- C++细节
- Data structure-String-Pattern match
- Linux下常用压缩格式的压缩与解压方法
- 春暖花开日,正是读书时——4月推荐给程序员们的书
- Oracle 字符集的查看和修改
- 一道笔试题引出基础知识漏洞
- 随想录(字节序和位序)
- 模型驱动架构(MDA,Model Driven Architecture)浅述
- 今天程序运行着无缘无故蹦掉了,原来犯了一个老毛病
- MFC中教你怎么编写弹出式菜单