given the list of words... what you can do is the following :- now take first word from the list.. sort this word in alphabetical order...for eg str=bcda ---> sort , we get str=abcd now considering this sorted word as a key(abcd) , insert original word (bcda as value) into the hash table ( hash table with chaining )
similarly do it for other words. now given a word , you just need to sort this given word and use it as a key to fetch all anagram. On Fri, May 11, 2012 at 5:24 PM, mayur <[email protected]> wrote: > Hi all, > > I am stuck with a question for a long time...can someone provide the best > algorithm for this.. > > Question).. find all the anagrams in a list of words. The algorithm should > be efficient as the list can be very large. > > -- > 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/-/c4cSIMcBYLEJ. > 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.
