@ above you approach trie needs lot of optimization.. this will take up lot of space...trie is suitable in case where we want to reduce search complexity and its space complexity is very bad.. so hashing should be better here as compared to trie..
i think shashank's solution is better... On Tue, Feb 1, 2011 at 7:15 PM, sankalp srivastava < [email protected]> wrote: > I think , as juver++ said , you should also try reading on the > internet about these kinds of problems .This can be solved with an > augmentation of a trie (keeping a count variable at the leaf > ( maintaining a counter for all the word frequencies > accordingly )) .Just print the top ten results in the end .time > complexity will be O(n , log n ) .We can improve upon this solution a > lot using other forms of tries and some augmentation > > PS:This will take some time if we do it for n characters , but since > you explicitly asked for 10 characters , so be it ! > > For your second question , try seraching "globbing" (For the > masochists , download the source code for glob library and go through > the code ) > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
