Trie is an efficient information retrieval data structure. In our previous post on trie we have discussed about basics of trie and how to insert and search a key in trie. In this post we will discuss about displaying all of the content of a trie. That is, to display all of the keys present in the Trie.
Input: If Trie is root / \ \ t a b | | | h n y | | \ | e s y e / | | i r w | | | r e e | r Output: Contents of Trie: answer any bye their there
The idea to do this is to start traversing from the root node of trie, whenever we find a NON-NULL child node, we add parent key of child node in the “string str” at the current index(level) and then recursively call the same process for the child node and same goes on till we find the node which is a leafnode, which actually marks the end of the string.
Below is the C++ implementation of above idea:
Content of Trie: a answer any by bye the their there
NOTE: The above algorithm displays the content of Trie in Lexographically Sorted order.
Some useful applications of Trie are:
- Implementing Auto-Correct and Auto complete Features
- Implementing a Dictionary
This article is contributed by Yash Singla. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Boggle | Set 2 (Using Trie)
- Trie | (Delete)
- Bottom-up traversal of a Trie
- Implement a Dictionary using Trie
- Search in a trie Recursively
- Trie | (Insert and Search)
- Insertion in a Trie recursively
- Persistent Trie | Set 1 (Introduction)
- Advantages of Trie Data Structure
- Auto-complete feature using Trie
- Count inversions in an array | Set 4 ( Using Trie )
- Counting the number of words in a Trie
- Pattern Searching using a Trie of all Suffixes
- Trie memory optimization using hash map
- Longest Common Prefix using Trie
Improved By : ManasChhabra2