第四章、串

目录:

课件:

1. 串

1.1 定义

1.1.1 串的定义

notion image
notion image

1.1.2 串 VS 线性表

notion image
notion image

1.2 基本操作

1.2.1 串的基本操作

notion image

1.2.2 串的比较操作

notion image
 

【拓展】字符集编码

notion image
 

【拓展】乱码问题

notion image
 

【小节知识总结】

notion image

1.3 串的存储结构

notion image

1.3.1 串的顺序存储

notion image
notion image

1.3.2 串的链式存储

notion image
notion image
notion image
notion image
notion image

1.3.3 串的堆存储

王道教材 P111
堆存储一一组连续的存储单元存放串值的字符序列,但它们的存储空间是在程序执行过程中动态分配得到

【小节知识总结】

notion image

2. 字符串的模式匹配

notion image
 
什么是模式匹配
notion image

2.1 朴素模式匹配算法

notion image
一直持续到
notion image
定位操作
notion image
notion image
notion image
notion image
一直持续到
notion image
 
亦有其余算法情况,不在此处列明,详见页首PDF-4.2.2文件,循环思想不变
 
notion image
notion image

【小节知识总结】

notion image

2.2 KMP算法

2.2.1 KMP算法

其实就是朴素算法的一种优化
 
notion image
notion image
notion image
notion image

【算法结论】

notion image

【代码实现】

notion image
notion image

2.2.2 朴素模式匹配 VS KMP算法

notion image

2.3 求next数组

notion image
notion image
notion image
notion image

2.4 KMP算法的优化

notion image
notion image
 
notion image
notion image
notion image
 
 
notion image
notion image

【补充学习旧版KMP】

notion image

【教材习题总结】

next数组的题型:
注:先求next值,再加一个就是next数组值
next值就是当前匹配元素,往前看的所有元素的“前缀”与“后缀”最长的相同的元素的长度
 
在探究KMP单个匹配次数时:
注意不要忽略匹配出错元素的移位二次匹配
 
  • Twikoo