Re: [algogeeks] Google Q : all anagrams next to each other
@ashish : couldnt get u.. can u give an example?? On Tue, May 22, 2012 at 5:45 PM, Prem Krishna Chettri hprem...@gmail.comwrote: What I Could possibly think of is For each string S1 that is an anagram of some string S, use Map and Store the Key Value as (S1,S). Now there is a trick here abt how to reduce Time Complexity here... Now its easy to put all string which has correspondence S next to each other. This is Simple one. Inplace.. Hv to think abt .. I doubt, as we need some space to get the anagrams Dude.. Prem On Tue, May 22, 2012 at 5:18 PM, Ashish Goel ashg...@gmail.com wrote: Write a method to sort an array of strings so that all the anagrams are next to each other. What i could think of is preparing a multi linked list( multimap) whereby the key for each string is the sorted representation of the string(eg if string is gac, its sorted representation is acg). Walk of all lists of this multimap to give all anagrams. Is there any other better solution for this problem? Can this be done *inplace*? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. 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.
[algogeeks] Google Q : all anagrams next to each other
Write a method to sort an array of strings so that all the anagrams are next to each other. What i could think of is preparing a multi linked list( multimap) whereby the key for each string is the sorted representation of the string(eg if string is gac, its sorted representation is acg). Walk of all lists of this multimap to give all anagrams. Is there any other better solution for this problem? Can this be done *inplace*? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. 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.
Re: [algogeeks] Google Q : all anagrams next to each other
What I Could possibly think of is For each string S1 that is an anagram of some string S, use Map and Store the Key Value as (S1,S). Now there is a trick here abt how to reduce Time Complexity here... Now its easy to put all string which has correspondence S next to each other. This is Simple one. Inplace.. Hv to think abt .. I doubt, as we need some space to get the anagrams Dude.. Prem On Tue, May 22, 2012 at 5:18 PM, Ashish Goel ashg...@gmail.com wrote: Write a method to sort an array of strings so that all the anagrams are next to each other. What i could think of is preparing a multi linked list( multimap) whereby the key for each string is the sorted representation of the string(eg if string is gac, its sorted representation is acg). Walk of all lists of this multimap to give all anagrams. Is there any other better solution for this problem? Can this be done *inplace*? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. 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.
Re: [algogeeks] Google Q : all anagrams next to each other
Anyways we need to sort all the words atleast once, one way is To travel throught the list sorting each word and making a pair of the orginal and the sorted word. For Ex. If one of the original word in list is aanchal sorted is aaachln. So store the pair aanchal, aaachln Now sort this list of pairs based on 2nd value. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. 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.