Overview
The Z Algorithm builds a Z-array that can be used for fast exact pattern matching and string analysis.
Computes how much each string suffix matches the string prefix.
Compact metadata for implementation and discovery.
The Z Algorithm builds a Z-array that can be used for fast exact pattern matching and string analysis.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(n)
Z[i] = longest prefix length matching string[i...]Stores how far the string prefix matches from each position.
Show a prefix match window reused across string positions.
Z Algorithm operates in O(n) time and O(n) space within the Linear String Preprocessing family. Key governing relation: Z[i] = longest prefix length matching string[i...]. Often compared with Knuth-Morris-Pratt and Suffix Array Search.
What each reference supports for this entry.
String algorithms reference covering Z Algorithm recurrences, automata/indexing structures, or exact/approximate matching role.
Good next jumps from the relationship graph, ranked for useful discovery.
Both use prefix information for exact pattern matching.
Z-values can support string preprocessing workflows.