知识卡片
重复字符使朴素匹配达到最坏界
每个候选位移最多比较m个字符,故朴素匹配最坏为Θ((n−m+1)m)。
例如文本和模式都由同一字符组成时,每个位移都要完成全部m次比较;m约为n/2时达到二次量级。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 第32章 字符串匹配 · 查看原书依据
Procedure NAIVE-STRING-MATCHER takes O((n – m + 1)m) time, and this bound is tight in the worst case. For example, consider the text string an (a string of na’s) and the pattern am. For each of the n−m+1 possible values of the shift s, the implicit loop on line 2 to compare corresponding characters must execute m times to validate the shift. The worst-case running time is thus Θ((n − m + 1)m), which is Θ(n2) if m = ⌊n/2⌋. Because it
参考来源
- 位置:《算法导论(第4版)》第32章《字符串匹配》(OEBPS/chapter032.xhtml,文本字符[5000,10000))。
- 结论依据:原文定义字符串匹配、前后缀或相应算法的比较规则;相关图式已核对。
- 原始内容:Procedure N AIVE -S TRING -M ATCHER takes O (( n – m + 1) m ) time, and this bound is tight in the worst case. For example, consider the text string a n (a string of n a ’s) and the pattern a m . For each of the n − m +1 possible values of the shift s , the implicit loop on line 2 to compare corresponding characters must execute m times to validate the shift. The worst-case running time is thus Θ(( n − m + 1) m ), which is Θ( n 2 ) if m = ⌊ n /2 ⌋ . Because it