Trie | (Display Content)
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 Lexicographically 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 write.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.