Search text efficiently with pattern-matching algorithms

8 steps · about 2 h 30 min · Intermediate

  1. Frame substring search as an algorithm problem (article, Princeton Algorithms, 15 min)

    Compare the main strategies and the work each avoids.

  2. Build and test the naive baseline (article, Princeton Algorithms, 15 min)

    A clear baseline makes later correctness and complexity gains measurable.

  3. Compute a pattern's prefix function (article, CP-Algorithms, 25 min)

    Derive the reusable border information behind linear-time KMP search.

  4. Implement KMP as a state machine (article, Princeton Algorithms, 25 min)

    Connect prefix reuse to an implementation that never backs up in the text.

  5. Search with a rolling hash (article, CP-Algorithms, 22 min)

    Learn how Rabin–Karp updates fingerprints and why matching hashes still need verification.

  6. Reason about collisions (article, CP-Algorithms, 20 min)

    Choose hash parameters and understand the residual collision risk instead of treating hashes as equality proofs.

  7. 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.

  8. Recognise when skipping ahead wins (article, Princeton Algorithms, 18 min)

    Finish by contrasting prefix and hash methods with right-to-left mismatch skipping.