时空权衡——字符串匹配(Time/Space Tradeoff
来源:互联网 发布:网络流行尴舞视频 编辑:程序博客网 时间:2024/05/17 07:51
时空权衡——字符串匹配(Time/Space Tradeoff - Horspool’s String Matching)
字符串匹配简介(Introduction)
String matching is to find a place where one or several strings(called pattern) are found within a large string or text. For example,
Text: STRINGSEARCH EXAM P
Pattern: EXAM
算法(Algorithm)
Before the actual matching process starts, we do some pre-processes of strings, which is also called input enhancement. Build a shift table to help matching.
For example,
Compare each character in the pattern from right to left. Shift the pattern “EXAM” 4 position to right since I is not in the pattern.
Shift 3 position because E in the text occurs in the first place in the pattern.
Shift 4 position cause C in the text is not in the pattern.
Shift 1 position because A in the text occurs in the third place in the pattern.
Here, we get match.
How many position to shift after comparison? - The answer is shift table.
Constructing Shift Table Pseudocode
function FindShifts(P[0..m-1]) for i ⟵ 0 to a do Shift[i] ⟵ m for j ⟵ 0 to m-1 do Shift[P[j]] ⟵ m-j-1
Horspool’s String Matching Algorithm Pseudocode
function Horspool(P[0..m-1], T[0..n-1]) FindShifts(P) i ⟵ m-1 while i < n do k ⟵ 0 while k < m and P[m-1-k] = T[i-k] do k ⟵ k + 1 if k = m then return i - m + 1 else i ⟵ i + Shift[T[i]] return -1
Java Code
I will update ASAP.
写在后面的话(PS)
There are three algorithms for string matching: Brute force algorithm, Horspool’s algorithm and Rabin-Karp algorithm. Understand each of them.
Welcome questions always and forever.
- 时空权衡——字符串匹配(Time/Space Tradeoff
- 时空权衡——哈希法(Time/Space Tradeoff
- 时空权衡——斐波那契数列(Time/Space Tradeoff
- 时空权衡
- 偏见方差的权衡(Bias Variance Tradeoff)
- bias与variance的权衡(tradeoff)
- 偏差-方差权衡(Bias-Variance Tradeoff)
- 机器学习算法中的偏差-方差权衡(Bias-Variance Tradeoff)
- 检测错误权衡图(Detection error tradeoff(DET))
- Understanding the Bias-Variance Tradeoff (理解偏差-方差权衡)
- Bias-Variance Tradeoff(权衡偏差与方差)
- 转:交叉验证和bias-tradeoff的权衡
- 字符串匹配 — Horspool
- 机器学习方差和偏差权衡(Understanding the Bias-Variance Tradeoff)
- 字符串匹配——KMP
- 字符串匹配——KMP
- CCF——字符串匹配
- 字符串匹配 — BM算法
- Lintcode[1]单例
- 理解 IntelliJ IDEA 的项目配置和Web部署
- prepareForSegue在什么时候会调用
- bzoj1042 硬币购物 容斥原理
- TCP/UDP常用端口及对应服务列表
- 时空权衡——字符串匹配(Time/Space Tradeoff
- 关于PHP高并发抢购系统设计
- stm32 DMA的Stream和Channel的映射关系(STM32F7)
- 高效分页 sql 存储过程 以及 执行
- UI 设计技巧
- python3遍历目录查找文件
- 在什么时候用assert?
- Centos7 以及Ubuntu中开机启动的设置以及查看
- 让他