While you are reading words from the file, maintain a hash table. For each word encountered, update the hash count. Once the input file is exhausted, sort the hash table in O(logN) and print the list.
A good hash function will be appreciated... else use the hash+=31*(*str) function and also keep a link list for colliding elements. Cheers!!! On Saturday, June 9, 2012 7:21:28 PM UTC+5:30, Navin Kumar wrote: > > Write an efficient program that prints the distinct words in its input > sorted into decreasing order of frequency of occurrence. Precede each word > by its count. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/iPALw9qZfl0J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.