Open In App

Applications, Advantages and Disadvantages of Trie

Trie(pronounced as “try”): Trie(also known as the digital tree or prefix tree) is a sorted and efficient tree-based special data structure that is used to store and retrieve keys in a dataset of strings. The basic ideology behind this is retrieving information. It is based on the prefix of a string. It can be visualized as a graph consisting of nodes and edges. Another name for Trie is the digital tree. Each node of a trie can have as many as 26 pointers/references.  These 26 pointers represent the 26 characters of the English language.

Basic Operations of  Trie:



Applications of Trie data structure: 

It has a wide variety of applications in data compression, computational biology, longest prefix matching algorithm used for routing tables for IP addresses, implementation of the dictionary, pattern searching, storing/querying XML documents, etc.

Real-time applications of Trie data structure:

1. Browser History: Web browsers keep track of the history of websites visited by the user So when the prefix of a previously visited URL is written in the address bar the user would be given suggestions of the website to visit.



Trie is used by storing the number of visits to a website as the key value and organizing this history on the Trie data structure  

Browser history suggestions(geeks for geeks)

2. AutoComplete: It is one of the most important applications of trie data structure. This feature speeds up interactions between a user and the application and greatly enhances the user experience. Auto Complete feature is used by web browsers, email, search engines, code editors, command-line interpreters(CLI), and word processors.

Trie provides the alphabetical ordering of data by keys. Trie is used because it is the fastest for auto-complete suggestions, even in the worst case, it is O(n) (where n is the string length ) times faster than the alternate imperfect hash table algorithm and also overcomes the problem of key collisions in imperfect hash tables.

Auto complete suggestions on entering prefix(geeks for geeks)

3. Spell Checkers/Auto-correct: It is a 3-step process that includes :

  1. Checking for the word in the data dictionary.
  2. Generating potential suggestions.
  3. Sorting the suggestions with higher priority on top.

Trie stores the data dictionary and makes it easier to build an algorithm for searching the word from the dictionary and provides the list of valid words for the suggestion.

Auto correct(geeks for geeks)

4. Longest Prefix Matching Algorithm(Maximum Prefix Length Match): This algorithm is used in networking by the routing devices in IP networking. Optimization of network routes requires contiguous masking that bound the complexity of lookup a time to O(n), where n is the length of the URL address in bits.

To speed up the lookup process, Multiple Bit trie schemes were developed that perform the lookups of multiple bits faster.

IP routing(geeks for geeks)

Advantages of Trie data structure:

Disadvantages of Trie data structure:

Article Tags :