I have a requirement to track the occurrence of the words in the text and this occurrence need to be arranged in the descending order. I initially used the hash map data structure however as I was researching further on, I discovered the "Trie" data structure.
I think "Trie" data structure is perfect for tracking the occurrence in terms of both flexibility and complexity. However there is one more requirements, I need to sort the occurrence in descending order. So basically traversing the "Trie" in depth first search.
Implementation wise this is little tricky, so I was wondering if I was in the right track. Any kind of opinion would be great. What would be the best data structure to use in this case?
Note: Sort order is descending in terms of occurrence so if "A" appeared 5 times and "B" appeared 2 times sort order should be "A", "B". Also two words with same occurrences would be sorted in alphabetical order.
Thanks