What is a Z Algorithm Visualizer?
A Z Algorithm visualizer shows how the Z-array is built for a combined string like pattern + delimiter + text. Each Z value stores how many characters from that position match the prefix of the combined string.
This tool lets you enter text and a pattern, then step through the Z-box, reused values, direct comparisons, and confirmed pattern match indexes.
For the full algorithm set, browse the Data Structure Visualizers hub.
How to use this Z Algorithm visualizer
- Enter the text to scan.
- Enter the pattern to search for.
- Click Run Z Algorithm to jump to the completed Z-array.
- Step forward to inspect the current index, active Z-box, comparison characters, and match output.
- Read any Z value greater than or equal to the pattern length after the delimiter as a match.
Z Algorithm vs KMP and Rabin-Karp
The Z Algorithm and KMP both use prefix information to avoid restarting a search from scratch. Z builds prefix-match lengths over one combined string, while KMP builds an LPS table for the pattern. Rabin-Karp uses rolling hashes instead of prefix lengths.
Compare this page with the KMP String Matching Visualizer, Rabin Karp Visualizer, and Edit Distance Visualizer.