Overview
The Two-Way algorithm computes a critical factorization of the pattern, then uses period information to skip safely while checking the right and left parts of the pattern.
Searches exactly by splitting the pattern at a critical factorization and scanning in two directions.
Compact metadata for implementation and discovery.
The Two-Way algorithm computes a critical factorization of the pattern, then uses period information to skip safely while checking the right and left parts of the pattern.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(n + m)
Worst
O(n + m)
Space
O(n + m)
Show splitting a pattern at a critical factorization and scanning both sides on a small exact string matching example.
Two-Way matching is valuable because it combines practical skipping with linear worst-case guarantees.
What each reference supports for this entry.
String algorithms reference for Two-Way String Matching's pattern matching, suffix indexing, alignment, or sequence-processing mechanism.
Open sourceTextbook support for Two-Way String Matching's algorithm family, complexity framing, and standard implementation concepts.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Pattern Matching · Core
Two-Way String Matching and Shift-And Algorithm solve related exact string matching problems with different assumptions and tradeoffs.
Compare with thisPattern Matching · Core
Two-Way String Matching and Shift-Or Algorithm solve related exact string matching problems with different assumptions and tradeoffs.
Compare with thisTwo-Way String Matching and Bit-Parallel Levenshtein solve related exact string matching problems with different assumptions and tradeoffs.
Two-Way String Matching and Shift-And Algorithm solve related exact string matching problems with different assumptions and tradeoffs.
Two-Way String Matching and Shift-Or Algorithm solve related exact string matching problems with different assumptions and tradeoffs.