← 返回卡片

原书出处

Introduction to Algorithms, Fourth Edition

32 第32章 字符串匹配

Fourth edition · 核验版本的摘录快照 · 导入于 2026-10-23T08:18:08.764Z

ow. Lines 2–6 compute p as the value of P[1:m] mod q and t0 as the value of T[1:m] mod q.

The for loop of lines 7–12 iterates through all possible shifts s, maintaining the following invariant: Whenever line 8 is executed, ts = T[s + 1:s + m] mod q. If a hit occurs because p = ts in line 8, then line 9 determines whether s is a valid shift or the hit was spurious via the test P[1:m] == T[s +1:s +m]. Line 10 prints out any valid shifts that are found. If s < n – m (checked in line 11), then the for

loop will iterate at least one more time, and so line 12 first executes to ensure that th

此预览只包含定位所需的摘录和上下文。

原书定位详情

来源:a19c7933-4eda-4176-aebd-30fe7e1ad292

正文位置:extracted/Introduction to Algorithms, Fourth Edition/_epub-src/OEBPS/chapter032.xhtml

EPUB SHA-256:ec7ced04bb875b93983816aef7a667855a4b71c5cf53b63406b9439c74e27aea