main page — COMP 526 Efficient Algorithms
Unit 4: String Matching – What’s behind Ctrl+F?
This is an archived version of this module from Spring 2021.
Click here for the current iteration.
This unit covers algorithms for exact string matching:
- terminology for strings
- string matching with determinstic finite automata
- Knuth-Morris-Pratt (KMP) algorithm
- Boyer-Moore (BM) algorithm
- Rabin-Karp (RK) algorithm
Learning outcomes
- Know and use typical notions for strings (substring, prefix, suffix, etc.).
- Understand principles and implementation of the KMP, BM, and RK algorithms.
- Know the performance characteristics of the KMP, BM, and RK algorithms.
- Be able to solve simple stringology problems using the KMP failure function.
Material
- slides
- lecture notes
- Video 4-1 · transcript (2021-03-03, 14:57): §4.1 Introduction
- Video 4-2 · transcript (2021-03-09, 12:32): §4.2 Brute force string matching
- Video 4-3 · transcript (2021-03-09, 15:26): §4.3 String matching with finite automata
- Video 4-4 · transcript (2021-03-09, 23:12): §4.3 Constructing string matching DFAs
- Video 4-5 · transcript (2021-03-09, 25:01): §4.4 The Knuth-Morris-Pratt algorithm
- Video 4-6 · transcript (2021-03-10, 31:01): §4.5 The Boyer-Moore algorithm
- Video 4-7 · transcript (2021-03-10, 20:18): §4.6 The Rabin-Karp algorithm
Further reading and sources
The naive string matching algorithm, string matching with automata and the Knuth-Morris-Pratt are discussed, e.g., in
The description of the Boyer-Moore algorithm follows my algorithms textbook (in German):
The presentation of Rabin-Karp and the failure-link automaton is inspired by material prepared for the module