Access the NEW Basecamp Support Portal


« Back to Glossary Index

History, etymology, and pronunciation
– Trie was first abstractly described by Axel Thue in 1912
– René de la Briandais described tries in a computer context in 1959
– Edward Fredkin independently described tries in 1960 and coined the term ‘trie’
– Some authors pronounce it as /ˈtriː/ (tree), while others pronounce it as /ˈtraɪ/ (try)
– The term ‘trie’ comes from the middle syllable of ‘retrieval’

Overview and Operations
– Tries are a form of string-indexed look-up data structure
– They are used to store a dictionary list of words
– Tries allow for efficient generation of completion lists
– They are particularly useful for string-searching algorithms like predictive text and spell checking
– Tries can be seen as tree-shaped deterministic finite automata
– Tries support insertion, deletion, and lookup of string keys
– Nodes in a trie contain links to other suffix child nodes or null
– Each node has a parent except for the root node
– The number of links in each node is equal to the number of characters in the alphabet
– Nodes in the trie do not store their associated key, but their position defines the key

Searching and Insertion
– Searching in a trie is guided by the characters in the search string key
– Each node in the trie contains a link to each possible character in the string
– Following the string within the trie leads to the associated value for the key
– A null link during the search indicates the key does not exist in the trie
– The search operation in a standard trie takes O(dm) time, where m is the size of the string key and d is the alphabet size
– Insertion into a trie involves using the characters in the string key as indexes to the children array
– Each node in the trie corresponds to one call of the radix sorting routine
– If a null link is encountered during insertion, a new node is created
– The value of the terminal node is assigned to the input value
– If the terminal node already had a value, it is replaced with the new value

Replacing other data structures and Implementation strategies
– A trie can replace a hash table
– Searching for a node in a trie has a complexity of O(m), while an imperfect hash function may have a worst-case lookup speed of O(N)
– Tries do not require a hash function and do not have collisions
– Tries can sort string keys using alphabetical ordering
– Tries are less efficient than hash tables when data is accessed on a secondary storage device
– Tries can be represented using a vector of pointers or a singly linked list for each node
– Techniques like alphabet reduction can reduce space complexity by using a smaller alphabet
– Storing a vector of ASCII pointers as a bitmap reduces the size of nodes
– Different implementation strategies have trade-offs between memory use and speed
– Memory space can be reduced at the expense of running time

Bitwise tries and Compressed tries
– Bitwise tries address the space requirement issue in naive pointer vector implementations
– Each character in the string key set is represented using individual bits
– Vectorized CPU instructions are used to find the first set bit in a fixed-length key input
– Bitwise tries are cache-local and highly parallelizable
– They perform well on out-of-order execution CPUs
– Radix tree, or compressed trie, is a space-optimized variant of a trie
– Nodes with only one child get merged with their parents, reducing space and time metrics
– Compressed tries work best when the trie remains static and keys are sparse
– Packing the trie can further optimize space usage
– Patricia trees are a binary encoding of string keys in a compressed binary trie

Note: The content did not provide enough information to create a comprehensive fifth group.

Trie (Wikipedia)

In computer science, a trie (/ˈtr/, /ˈtr/), also called digital tree or prefix tree, is a type of k-ary search tree, a tree data structure used for locating specific keys from within a set. These keys are most often strings, with links between nodes defined not by the entire key, but by individual characters. In order to access a key (to recover its value, change it, or remove it), the trie is traversed depth-first, following the links between nodes, which represent each character in the key.

Invented byEdward Fredkin, Axel Thue, and René de la Briandais
Time complexity in big O notation
Operation Average Worst case
Search O(n) O(n)
Insert O(n) O(n)
Delete O(n) O(n)
Space complexity
Space O(n) O(n)
Depiction of a trie. Single empty circle, representing the root node, points to three children. The arrow to each child is marked by a different letter. The children themselves have similar set of arrows and child nodes, with nodes that correspond to full words bearing blue integer values.
A trie for keys "A", "to", "tea", "ted", "ten", "i", "in", and "inn". Each complete English word has an arbitrary integer value associated with it.

Unlike a binary search tree, nodes in the trie do not store their associated key. Instead, a node's position in the trie defines the key with which it is associated. This distributes the value of each key across the data structure, and means that not every node necessarily has an associated value.

All the children of a node have a common prefix of the string associated with that parent node, and the root is associated with the empty string. This task of storing data accessible by its prefix can be accomplished in a memory-optimized way by employing a radix tree.

Though tries can be keyed by character strings, they need not be. The same algorithms can be adapted for ordered lists of any underlying type, e.g. permutations of digits or shapes. In particular, a bitwise trie is keyed on the individual bits making up a piece of fixed-length binary data, such as an integer or memory address. The key lookup complexity of a trie remains proportional to the key size. Specialized trie implementations such as compressed tries are used to deal with the enormous space requirement of a trie in naive implementations.

« Back to Glossary Index

Request an article

Please let us know what you were looking for and our team will not only create the article but we'll also email you to let you know as soon as it's been published.
Most articles take 1-2 business days to research, write, and publish.
Content/Article Request Form

Submit your RFP

We can't wait to read about your project. Use the form below to submit your RFP!
Request for Proposal

Contact and Business Information

Provide details about how we can contact you and your business.

Quote Request Details

Provide some information about why you'd like a quote.