Search text efficiently with pattern-matching algorithms
8 steps · about 2 h 30 min · Intermediate
- Frame substring search as an algorithm problem (article, Princeton Algorithms, 15 min)
Compare the main strategies and the work each avoids.
- Build and test the naive baseline (article, Princeton Algorithms, 15 min)
A clear baseline makes later correctness and complexity gains measurable.
- Compute a pattern's prefix function (article, CP-Algorithms, 25 min)
Derive the reusable border information behind linear-time KMP search.
- Implement KMP as a state machine (article, Princeton Algorithms, 25 min)
Connect prefix reuse to an implementation that never backs up in the text.
- Search with a rolling hash (article, CP-Algorithms, 22 min)
Learn how Rabin–Karp updates fingerprints and why matching hashes still need verification.
- Reason about collisions (article, CP-Algorithms, 20 min)
Choose hash parameters and understand the residual collision risk instead of treating hashes as equality proofs.
- Test edge cases in a second KMP implementation (article, Princeton Algorithms, 10 min)
Compare implementation choices and define behaviour for empty, repeated and missing patterns.
- Recognise when skipping ahead wins (article, Princeton Algorithms, 18 min)
Finish by contrasting prefix and hash methods with right-to-left mismatch skipping.