Back to Dashboard
Patricia Tree
A memory-efficient compressed trie where nodes with only one child are merged with their parents, reducing the number of nodes for string storage.
Active
Target
Pivot
idle
Initializing...
Time Complexity
Best
Average
Worst
Space Complexity
StabilityFALSE
In-placeFALSE
Explanation
Patricia Tree (Compressed Trie)
A Patricia Tree (Practical Algorithm to Retrieve Information Coded in Alphanumeric) is a specialized dictionary based on the trie that is extremely space-efficient. It compresses a trie by merging nodes that have only one child with their parents.
Key Features
- Space Efficiency: By compressing paths with single children, it significantly reduces the number of nodes compared to a standard Trie.
- Prefix Matching: Like a Trie, it is excellent for prefix-based searches and autocomplete features.
- Edge Labels: Instead of storing a single character per edge, a Patricia Tree stores strings (sequences of characters) on its edges.
How it works
When inserting a word, if the algorithm encounters a node where the existing prefix matches the word being inserted, it either:
- Continues down if the match is complete.
- Splits the node if only a part of the prefix matches.
Pseudo Code
1procedure insert(word)2 node = root3 find common prefix among children4 if common prefix exists:5 if exact match:6 recurse into child7 else:8 split child node at common prefix9 add new child for remaining word10 else:11 add new leaf node12end procedure
Sponsor Ad