data-structures string-algorithms
Definition
Trie
A trie is a rooted tree that represents a finite set of strings over an alphabet .
Each edge is labelled by one letter from , and outgoing edges of the same node have pairwise distinct labels. The root represents the empty string . For any node , the concatenation of edge labels on the path from the root to is the prefix represented by .
A node is marked as terminal iff its represented prefix is a string in .
Compressed Trie
Definition
Link to originalCompressed Trie
Examples
Word membership
Let .
The string is in because the path
ends in a terminal node. The string is not in if the node for is not terminal, even though it is a prefix of stored strings.
Shared prefixes