Given an array of strings, print them in alphabetical (dictionary) order. If there are duplicates in input array, we need to print them only once.
Input : "abc", "xy", "bcd" Output : abc bcd xy Input : "geeks", "for", "geeks", "a", "portal", "to", "learn", "can", "be", "computer", "science", "zoom", "yup", "fire", "in", "data" Output : a be can computer data fire for geeks in learn portal science to yup zoom
Trie is an efficient data structure used for storing data like strings. To print the string in alphabetical order we have to first insert in the trie and then perform preorder traversal to print in alphabetical order.
abc bcd xy
This article is contributed by Pranav. 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.
- Sorting array of strings (or words) using Trie | Set-2 (Handling Duplicates)
- Palindrome pair in an array of words (or strings)
- Counting the number of words in a Trie
- Print all possible combinations of words from Dictionary using Trie
- Count the number of words with given prefix using Trie
- Check if the given Trie contains words starting from every alphabet
- Sort an array of strings based on the frequency of good words in them
- Print Strings In Reverse Dictionary Order Using Trie
- Count words that appear exactly two times in an array of words
- Sorting Strings using Bubble Sort
- Case-specific Sorting of Strings
- Case-specific sorting of Strings in O(n) time and O(1) space
- Python program to find uncommon words from two Strings
- Count inversions in an array | Set 4 ( Using Trie )
- Search in an array of strings where non-empty strings are sorted