I remember learning about this in a data structures class, and it is a remarkable data structure. But the author of this article needs to pick up a copy of Strunk and White. This reads like it was written by a high school junior. Awful, awful writing.
The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
31–40 of 42 posts
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#321. Given a set of strings, put all the suffixes into a set. For example "derp" -> "derp", "erp", "rp", "p".
2. Sort it
It's cheap! The number of suffixes equals the string length, and suffixes can be mere references into the string input. So in practice you use maybe ~2x memory compared to the input - and in big cache friendly chunks (not tries).
Now you're flying. If you want to perform a substring search:
1. Binary search on the first character. You get a range of suffixes which begin with that character.
2. Within that range, perform a binary search on the second character. Now you have a range of suffixes which begin with the first two characters.
3. etc.
Powerful and easy.
By the way this technique of going character by character can and should be extended to the sort itself; look up "three-way radix quicksort" for what you never learned in school.
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#33In practice one should typically prefer a suffix array to a suffix tree. A suffix array is conceptually so easy! 1. Given a set of strings, put all the suffixes into a set. For example "derp" -> "derp", "erp", "rp", "p". 2. Sort it It's cheap! The number of suffixes equals the string length, and suffixes can be mere references into the string input. So in practice you use maybe ~2x memory compared to the input - and…
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#34Earlier quoted context omitted.
The only thing suffix trees have in common with B-tries that I can see is that they're both non-binary trees. A B-tree stores whole keys in the nodes, not fragments of values. And a B-tree tries to self-balance, so there's a lot of leeway for what keys get pushed up to the root node. B-trees split and merge nodes based on the number of items in them, trying to achieve a certain fill factor. A suffix tree, on the othe…
I should phrase it differently; what does a suffix tree get you that a standard sorting tree doesn't get you. A standard sorting tree would get you all the neighbors in lexical order. What more do you need?
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#35Earlier quoted context omitted.
The prefix tree of a string is just a linked list, though—it's the string itself. It doesn't help you do anything for a single string, unlike a suffix tree, which is used for finding substrings of a single string. Moreover, how would you even start searching for a substring using a prefix tree? You can't start at the root, because the substring wouldn't be a prefix. It doesn't help you there at all.
This is such a clear and illuminating explanation as to why _suffix_, rather than prefix trees, are so useful.
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#36Earlier quoted context omitted.
I should phrase it differently; what does a suffix tree get you that a standard sorting tree doesn't get you. A standard sorting tree would get you all the neighbors in lexical order. What more do you need?
The B-tree just lets you quickly find out if a given string is in a set. The suffix tree lets you do things like finding the longest common substring very quickly, or looking for repeating motifs.
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#37This might be a stupid question: why is the fact it’s a _suffix_ tree important? (as opposed to building a similar structure with prefixes)
A suffix tree contains a compact trie like graph representation of all the suffixes of a long string. So if you want to know if it contains a substring, you can start at the root and just search like in a prefix tree. Since for the queried word to be an infix it must be a prefix of a suffix, you will find the word in O(|query|) time. So yeah its a prefix tree, but a prefix tree of all the suffixes. And now to answer…
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#38Earlier quoted context omitted.
A suffix tree contains a compact trie like graph representation of all the suffixes of a long string. So if you want to know if it contains a substring, you can start at the root and just search like in a prefix tree. Since for the queried word to be an infix it must be a prefix of a suffix, you will find the word in O(|query|) time. So yeah its a prefix tree, but a prefix tree of all the suffixes. And now to answer…
Why can't one construct a prefix tree of all prefixes, then start process from the right to left (assume that it is an offline algorithm)?
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#39This might be a stupid question: why is the fact it’s a _suffix_ tree important? (as opposed to building a similar structure with prefixes)
[1]https://pdfs.semanticscholar.org/d339/0f13eed511cde1116446e7...
Re: The Wonders of the Suffix Tree Through the Lens of Ukkonen’s Algorithm
#40I remember learning about this in a data structures class, and it is a remarkable data structure. But the author of this article needs to pick up a copy of Strunk and White. This reads like it was written by a high school junior. Awful, awful writing.
It seems like the style of the article is deliberately long-winded and poetic to match the type of content that the “human readable magazine” is going for (similar to New Yorker articles). It’s likely seeking to cater to a specific niche of reader preferences.