原书出处
Introduction to Algorithms, Fourth Edition
32 第32章 字符串匹配
ly, you can compute t0 from T[1:m] in Θ(m) time. To compute the remaining values t1, t2, …
, tn–m in Θ(n – m) time, observe that you can compute ts+1 from ts in constant time, since Subtracting 10m−1T [s + 1] removes the high-order digit from ts, multiplying the result by 10 shifts the number left by one digit position, and adding T[s + m + 1] brings in the appropriate low-order digit. For example, suppose that m = 5, ts = 31415, and the new low-order digit is T[s + 5 + 1] = 2. The high-order digit to remove is
T[s + 1] = 3, and so ts+1 = 10 (31415 − 10000 · 3) + 2 = 14152. If you precompute the con
原书定位详情
来源:a19c7933-4eda-4176-aebd-30fe7e1ad292
正文位置:extracted/Introduction to Algorithms, Fourth Edition/_epub-src/OEBPS/chapter032.xhtml
EPUB SHA-256:ec7ced04bb875b93983816aef7a667855a4b71c5cf53b63406b9439c74e27aea