I am reading about Tries
commonly known as Prefix trees and Suffix Trees
.
Although I have found code for a Trie
I can not find an
If you imagine a Trie in which you put some word's suffixes, you would be able to query it for the string's substrings very easily. This is the main idea behind suffix tree, it's basically a "suffix trie".
But using this naive approach, constructing this tree for a string of size n would be O(n^2) and take a lot of memory.
Since all the entries of this tree are suffixes of the same string, they share a lot of information, so there are optimized algorithms that allows you to create them more efficiently. Ukkonen's algorithm, for example, allows you to create a suffix tree online in O(n) time complexity.