The following introduction is copied from Wikipedia:
In computer science, a trie, also called digital tree or sometimes radix tree or prefix tree (as they can be searched by prefixes), is an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings.
Trie is a good choice for bioinformatic applications (for DNA sequence alighment). Also because trie supports ordered traversal, outputing all keys in the trie is actually a pre-order traversal. So obviously trie can be used for sorting, for example Burstsort, it’s even faster than quicksort for large data sets ( Worst case: ).
A simple trie tree looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
Problems
The above implemetation does not use space efficiently. The space complexity is , m = 26 for just English characters, and things get even worse when deal with unicode characters.
Follow-ups and references
- Tripple array trie and double array trie
- http://en.wikipedia.org/wiki/Ternary_search_tree
- BK-tree is an interesting data structure for fuzzy string search, popular for spell checking, see also Damn Cool Algorithms, Part 1: BK-Trees
- http://en.wikipedia.org/wiki/Patricia_tree
- 双数组Trie树原理
- A Succinct Trie, this is a very impressive way to encode trie with bit strings, uses the Succinct data structure.
- Space-efficient Static Trees and Graphs Guy Jacobson