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 firstname.lastname@example.org. 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.
- Trie | (Delete)
- Boggle | Set 2 (Using Trie)
- Implement a Dictionary using Trie
- Insertion in a Trie recursively
- Search in a trie Recursively
- Persistent Trie | Set 1 (Introduction)
- Trie | (Insert and Search)
- Bottom-up traversal of a Trie
- Longest Common Prefix using Trie
- Pattern Searching using a Trie of all Suffixes
- Program for assigning usernames using Trie
- Count inversions in an array | Set 4 ( Using Trie )
- Advantages of Trie Data Structure
- Auto-complete feature using Trie
- Trie memory optimization using hash map
Improved By : ManasChhabra2