Prefix Tries and Path Compression
Use prefix structure to answer exact and prefix queries and compress unary runs without losing key boundaries.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Following a path represents consuming a prefix
In a trie over a fixed alphabet, each edge consumes one symbol. A terminal flag states whether that prefix is a stored key. Inserting “atom” and “atomic” creates overlapping paths and requires separate terminal flags. To enumerate all stored keys beginning with “ato”, reach the prefix state and traverse its descendants. The work then depends on the prefix length, transition representation and number of reported characters.
Unary chains can become edge labels
A maximal chain with no branch and no key boundary can be stored as a string segment on one edge. A prefix query can finish inside the label, while an exact query must end at a terminal state. On insertion, split a label at the first mismatch or new key end. This saves nodes on sparse strings and adds comparisons inside edges. Finite automata share the idea of reading symbols through states. Radix sorting organizes the same kind of keys by digits without keeping a maintained trie.[1]