Efficient string pattern matching and manipulation algorithms.
1 algorithm
String algorithms answer questions about text: where a word appears in a document, whether a DNA sequence contains a marker, which log lines hold an error code. The core job is pattern matching, finding every place a short pattern occurs inside a longer text. It is what the find box in an editor does, and it turns up in interviews both directly and inside problems about repeated substrings and palindromes.
The obvious matcher tries every start position in the text and compares the pattern from scratch each time, which costs O(N times M) on repetitive text. Faster matchers reuse what earlier comparisons already proved. KMP does it by studying the pattern before searching. Rabin-Karp keeps a rolling hash of the current window and updates it in O(1) per step. Aho-Corasick builds the KMP fallback idea into a trie so it can look for many patterns at once.
KMP is the one to learn first, because its fallback idea returns in other places. Pick it when you need a linear time guarantee for one pattern; for several patterns of one length, Rabin-Karp is easier to extend, though hash collisions can slow it. Other sections cover nearby string work. The Trie section stores many words so that following a prefix takes one step per letter, however many words are stored. The Hash Map section has Valid Anagram, which compares letter counts rather than order. Valid Palindrome, under Array Techniques, checks a string with two pointers. After KMP, try the sliding window pages, which move along an array without stepping back, much as KMP moves along the text.