Open In App

Trie meaning in DSA

Last Updated : 28 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Trie data structure is defined as a Tree based data structure that is used for storing some collection of strings and performing efficient search operations on them. 

The word Trie is derived from reTRIEval, which means finding something or obtaining it. 

Representation of trie is similar to a tree data structure with a root node connected to its elements in a structured way with leaf nodes representing the end.

Trie Data Structure

Trie Data Structure

Properties of Trie:

  • Prefix-based: Tries are prefix-based data structures that can efficiently handle prefix matching, prefix searching, and prefix deletion.
  • Tree-based: Trie is a tree-structured data structure making it easily representable. 
  • Fast-Search: Trie has search time complexity O(m), where m is the length of the key.
  • Memory requirement: Trie has more space requirements, but it can be optimized,  
  • Easy to implement: Its iterative approach makes it easier to implement.

Applications of Trie:

Trie is involved wherever string manipulation or processing is involved. Here are a few usages of trie: 

  • Autocomplete: Tries are commonly used in auto-complete applications, such as when typing in a search bar.
  • Spell checking: By storing a large dictionary of words in a trie, it can be used to quickly check if a given word is spelled correctly.
  • IP routing: Tries are also used in IP routing, where the prefix of an IP address is used to determine the network address to forward packets.
  • Text compression: Tries can also be used in text compression algorithms such as Huffman coding.

Advantages of Trie:

  • Tries can be optimized to use less memory by compressing common prefixes into a single node, reducing the overall size of the data structure.
  • Tries can easily handle partial matches, prefix searches, and autocomplete operations.
  • Tries offer fast and efficient search operations for large collections of strings or words. For example, to search a single name in a student database of universities.
  • Tries can store additional data associated with each key in the leaf nodes, making it easy to access additional information about the keys.

Disadvantages of Trie:

  • Tries can be memory-intensive, especially for large collections of long strings, as each node requires additional memory to store its character value and pointer references.
  • Tries may require extra time and space to build or update the data structure when keys are added or deleted.
  • Tries may be slower than hash tables or binary search trees for exact match operations.

What else can you read?


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads