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 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.
- 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
- Count words that appear exactly two times in an array of words
- Sorting Strings using Bubble Sort
- Python program to find uncommon words from two Strings
- Search in an array of strings where non-empty strings are sorted
- Row wise sorting in 2D array
- Sorting all array elements except one
- Sorting array using Stacks
- Sorting an array according to another array using pair in STL
- Sorting Array Elements By Frequency | Set 3 (Using STL)
- Sorting array with conditional swapping
- Sorting array except elements in a subarray
- Check if the given string of words can be formed from words present in the dictionary