Trie

« 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.

Trie
TypeTree
Invented1960
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

Submit your RFP

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

Gabrielle Buff
Gabrielle Buff

Just left us a 5 star review

Great customer service and was able to walk us through the various options available to us in a way that made sense. Would definitely recommend!

Stoute Web Solutions has been a valuable resource for our business. Their attention to detail, expertise, and willingness to help at a moment's notice make them an essential support system for us.

Paul and the team are very professional, courteous, and efficient. They always respond immediately even to my minute concerns. Also, their SEO consultation is superb. These are good people!

Paul Stoute & his team are top notch! You will not find a more honest, hard working group whose focus is the success of your business. If you’re ready to work with the best to create the best for your business, go Stoute Web Solutions; you’ll definitely be glad you did!

Wonderful people that understand our needs and make it happen!

Paul is the absolute best! Always there with solutions in high pressure situations. A steady hand; always there when needed; I would recommend Paul to anyone!

facebook
Vince Fogliani
recommends

The team over at Stoute web solutions set my business up with a fantastic new website, could not be happier

facebook
Steve Sacre
recommends

If You are looking for Website design & creativity look no further. Paul & his team are the epitome of excellence.Don't take my word just refer to my website "stevestours.net"that Stoute Web Solutions created.This should convince anyone that You have finally found Your perfect fit

facebook
Jamie Hill
recommends

Paul and the team at Stoute Web are amazing. They are super fast to answer questions. Super easy to work with, and knows their stuff. 10,000 stars.

Paul and the team from Stoute Web solutions are awesome to work with. They're super intuitive on what best suits your needs and the end product is even better. We will be using them exclusively for our web design and hosting.

facebook
Dean Eardley
recommends

Beautifully functional websites from professional, knowledgeable team.

Along with hosting most of my url's Paul's business has helped me with website development, graphic design and even a really cool back end database app! I highly recommend him as your 360 solution to making your business more visible in today's social media driven marketplace.

I hate dealing with domain/site hosts. After terrible service for over a decade from Dreamhost, I was desperate to find a new one. I was lucky enough to win...

Paul Stoute has been extremely helpful in helping me choose the best package to suite my needs. Any time I had a technical issue he was there to help me through it. Superb customer service at a great value. I would recommend his services to anyone that wants a hassle free and quality experience for their website needs.

Paul is the BEST! I am a current customer and happy to say he has never let me down. Always responds quickly and if he cant fix the issue right away, if available, he provides you a temporary work around while researching the correct fix! Thanks for being an honest and great company!!

Paul Stoute is absolutely wonderful. Paul always responds to my calls and emails right away. He is truly the backbone of my business. From my fantastic website to popping right up on Google when people search for me and designing my business cards, Paul has been there every step of the way. I would recommend this company to anyone.

I can't say enough great things about Green Tie Hosting. Paul was wonderful in helping me get my website up and running quickly. I have stayed with Green...