# Types of Tries

A trie is a tree-like information retrieval data structure whose nodes store the letters of an alphabet. It is also known as a digital tree or a radix tree or prefix tree. Tries are classified into three categories:

** Standard Trie** A standard trie have the following properties:

- A Standard Trie has the below structure:
class Node { // Array to store the nodes of a tree Node[] children = new Node[26]; // To check for end of string boolean isWordEnd; }

- It is an ordered tree like data structure.
- Each node(except the
**root**node) in a standard trie is labeled with a character. - The children of a node are in alphabetical order.
- Each node or branch represents a possible character of keys or words.
- Each node or branch may have multiple branches.
- The last node of every key or word is used to mark the end of word or node.

Below is the illustration of the Standard Trie:

** Compressed Trie** A Compressed trie have the following properties:

- A Compressed Trie has the below structure:
class Node { // Array to store the nodes of tree Node[] children = new Node[26]; // To store the edgeLabel StringBuilder[] edgeLabel = new StringBuilder[26]; // To check for end of string boolean isEnd; }

- A Compressed Trie is an advanced version of the standard trie.
- Each nodes(except the
**leaf**nodes) have atleast 2 children. - It is used to achieve space optimization.
- To derive a Compressed Trie from a Standard Trie, compression of chains of redundant nodes is performed.
- It consists of grouping, re-grouping and un-grouping of keys of characters.
- While performing the insertion operation, it may be required to un-group the already grouped characters.
- While performing the deletion operation, it may be required to re-group the already grouped characters.
- A compressed trie T storing s strings(
**keys**) has s external nodes and O(s) total number of nodes.

Below is the illustration of the Compressed Trie:

** Suffix Trie** A Suffix trie have the following properties:

- A Compressed Trie has the below structure:
struct SuffixTreeNode { // Array to store the nodes struct SuffixTreeNode *children[256]; //pointer to other node via suffix link struct SuffixTreeNode *suffixLink; // (start, end) interval specifies the edge, // by which the node is connected to its // parent node int start; int *end; // For leaf nodes, it stores the index of // Suffix for the path from root to leaf int suffixIndex; }

- A Suffix Trie is an advanced version of the compressed trie.
- The most common application of suffix trie is Pattern Matching.
- While performing the insertion operation, both the word and its suffixes are stored.
- A suffix trie is also used in word matching and prefix matching.
- To generate a suffix trie, all the suffixes of given string are considered as individual words.
- Using the suffixes, compressed trie is built.

Below is the illustration of the Suffix Trie:

## Recommended Posts:

- Automation and its Types
- R - Data Types
- Types and Applications of LED
- Types of Array Processor
- Types of Cache Misses
- Types of Static Analysis Methods
- Types of Normal Forms in DBMS
- Minimum cost of reducing Array by merging any adjacent elements repetitively
- History of Computer Games
- Finding shortest path between any two nodes using Floyd Warshall Algorithm
- How to get user location in Android
- Cartoon animation loader using CSS
- Similarities and Difference between Java and C++
- Isomorphism in N-ary Trees

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.