知识卡片

普通读书笔记卡 · 3704.d

KMP用前缀数组替代全转移表

理解等级:中级

KMP只预处理模式的前缀函数π,需Θ(m)时间与m个数组项;失配时按π在扫描过程中摊还地求下一状态。

相较显式保存Θ(m|Σ|)个转移项,预处理不再随字母表大小成倍增长。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 第32章 字符串匹配 · 查看原书依据

      Knuth, Morris, and Pratt developed a linear-time string matching algorithm that avoids computing the transition function δ altogether. Instead, the KMP algorithm uses an auxiliary function π, which it precomputes from the pattern in Θ(m) time and stores in an array π[1:m]. The array π allows the algorithm to compute the transition function δ efficiently (in an amortized sense) “on the fly” as needed. Loosely speaking, for any state q = 0, 1,

    参考来源

    - 位置:《算法导论(第4版)》第32章《字符串匹配》(OEBPS/chapter032.xhtml,文本字符[35000,40000))。 - 结论依据:原文第32.3–32.4节对应引理、转移表或前缀函数推导;图式已核对。 - 原始内容:Knuth, Morris, and Pratt developed a linear-time string matching algorithm that avoids computing the transition function δ altogether. Instead, the KMP algorithm uses an auxiliary function π , which it precomputes from the pattern in Θ( m ) time and stores in an array π [1: m ]. The array π allows the algorithm to compute the transition function δ efficiently (in an amortized sense) “on the fly” as needed. Loosely speaking, for any state q = 0, 1, …, m and any character a ∈ ∑, the value π [ q ]