The lead section of this article may need to be rewritten. Advanced data structures peter brass pdf discuss this issue on the article’s talk page.
Use the lead layout guide to ensure the section follows Wikipedia’s norms and to be inclusive of all essential details. This article is about a tree data structure.
For the French commune, see Trie-sur-Baïse. A trie for keys “A”,”to”, “tea”, “ted”, “ten”, “i”, “in”, and “inn”.
All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. Values are not necessarily associated with every node. Rather, values tend only to be associated with leaves, and with some inner nodes that correspond to keys of interest. For the space-optimized presentation of prefix tree, see compact prefix tree.
In the example shown, keys are listed in the nodes and values below them. Each complete English word has an arbitrary integer value associated with it. A trie can be seen as a tree-shaped deterministic finite automaton.
Each finite language is generated by a trie automaton, and each trie can be compressed into a deterministic acyclic finite state automaton. Though tries are usually keyed by character strings, they need not be.
The same algorithms can be adapted to serve similar functions of ordered lists of any construct, e. In particular, a bitwise trie is keyed on the individual bits making up any fixed-length binary datum, such as an integer or memory address. Tries were first described by René de la Briandais in 1959. As discussed below, a trie has a number of advantages over binary search trees.
An imperfect hash table can have key collisions. A key collision is the hash function mapping of different keys to the same position in a hash table.
There are no collisions of different keys in a trie. Buckets in a trie, which are analogous to hash table buckets that store key collisions, are necessary only if a single key is associated with more than one value. There is no need to provide a hash function or to change hash functions as more keys are added to a trie. A trie can provide an alphabetical ordering of the entries by key.