Aho-Corasick string matching algorithm
My friend recently wrote a blog post about the Aho-Corasick string matching algorithm. I got inspired by her post, and I got bored during class, so I coded up a simple Javascript demo that dynamically generates a visualization of the trie data structure.
Type some words separated by spaces in the input field below and watch the diagram change in real time!
Each blue edge connects a node to its suffix in the trie, if it exists. Each green edge connects a node to its largest suffix that is a valid word, i.e. if you follow the blue edges upwards until you reach encounter the first node that is blue and not grey, you would have found the node connected via the green edge.
To save the image, simply copy the SVG code from below, paste it into your favourite text editor, and save it as an SVG file, for example, trie.svg
.