@Karthikeyan : i have little doubt in you algorithm... acc to the question input stream is the stream of numbers not words.
now if we consider Trie , first you have to extract digits from each input number and use those digit to created trie. so how will you get k most frequent occurring words in O(n) ??? On Sat, Dec 17, 2011 at 11:38 PM, Karthikeyan V.B <[email protected]>wrote: > Trie data structure can be used... > > In the trie, you can record item count in each node representing frequency > of word consisting of characters on the path from root to current node. > > The time complexity to setup the trie is O(Ln) (where L is number of > characters in the longest item). To find the top k items, we can traversal > the trie, which also costs O(n). So it takes O(n) to solve this problem. > > > > Regards, > > KARTHIKEYAN.V.B > > PSGTECH > > CBE > > -- > 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. > -- 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.
