Implement a dictionary using Trie such that if the input is a string representing a word, the program prints its meaning from the prebuilt dictionary.
Input: str = “map”
Output: a diagrammatic representation of an area
Input: str = “language”
Output: the method of human communication
Approach: We can use a Trie to efficiently store strings and search them. Here, an implementation of a dictionary using Trie (memory optimization using hash-map) is discussed. We add another field to Trie node, a string which will hold the meaning of a word. While searching for the meaning of the required word, we search for the word in Trie and if the word is present (i.e isEndOfWord = true) then we return its meaning otherwise we return an empty string.
Below is the implementation of the above approach:
a diagrammatic representation of an area
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print all possible combinations of words from Dictionary using Trie
- Print Strings In Reverse Dictionary Order Using Trie
- Auto-complete feature using Trie
- Pattern Searching using a Trie of all Suffixes
- Find shortest unique prefix for every word in a given list | Set 1 (Using Trie)
- Longest Common Prefix using Trie
- Count of distinct substrings of a string using Suffix Trie
- Boggle | Set 2 (Using Trie)
- Trie memory optimization using hash map
- Sorting array of strings (or words) using Trie
- Sorting array of strings (or words) using Trie | Set-2 (Handling Duplicates)
- Program for assigning usernames using Trie
- Trie Data Structure using smart pointer and OOP in C++
- Count inversions in an array | Set 4 ( Using Trie )
- Count the number of words with given prefix using Trie
- Trie | (Insert and Search)
- Trie | (Delete)
- Longest prefix matching - A Trie based solution in Java
- Overview of Data Structures | Set 3 (Graph, Trie, Segment Tree and Suffix Tree)
- Trie | (Display Content)
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.