Sign each word such that two words having same signature are anagrams of
each other.
The signature for every word can be :- given word in lexicographically
sorted order.
Keep a trie data structure to store all the signatures.
Now every leaf node points to a list having all the words which are
@prem can u plz explain the variables used in the modified structure...n if
m nt wrong then ur sol can result in repeated anagrams if characters in the
words are repeated
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this
Well this is an Age old question yet there seems to have a lots of room for
further modification..
1 Comparison of String Individually. Effective yet O(n2)
2 Why dont we let some function do the job say
if( Sort(String 1)==Sort(String 2))
@payal instead corresponding ascaii, corresponding primes can be taken
(preDefined) as explaind in my previous post.
On Tue, May 15, 2012 at 12:02 AM, payal gupta gpt.pa...@gmail.com wrote:
hmm...
thnx for the catch of my flaw...
On Mon, May 14, 2012 at 11:56 PM, saurabh singh
@ deepikaanand:
I would like to paraphrase Gaurav's approach:
what u have to do is take array a[26]={2,3,5,7,11. first 26
prime numbers }
Now if ur words are EAT and ATE:
for EAT..
val1= a[ 'E' - 'A' ] * a [ 'A' - 'A' ] * a[ ' T '- 'A' ];
for ATE:
val2= a[ 'A' - 'A' ] * a [ 'T' -
@atul
instead of sorting the string individually which would require tc- O(nlogn)
shouldnot it be a better idea to use the sum of the ascii values of the
individual alphabets as the key which would require tc-O(n) ???
On Sun, May 13, 2012 at 7:07 PM, GAURAV CHAWLA togauravcha...@gmail.comwrote:
u mean ad == bc ?
On Mon, May 14, 2012 at 10:41 PM, payal gupta gpt.pa...@gmail.com wrote:
@atul
instead of sorting the string individually which would require tc-
O(nlogn) shouldnot it be a better idea to use the sum of the ascii values
of the individual alphabets as the key which would
hmm...
thnx for the catch of my flaw...
On Mon, May 14, 2012 at 11:56 PM, saurabh singh saurabh.n...@gmail.comwrote:
u mean ad == bc ?
On Mon, May 14, 2012 at 10:41 PM, payal gupta gpt.pa...@gmail.com wrote:
@atul
instead of sorting the string individually which would require tc-
Ah but this isn't a key because ac would have the same ascii sum as
bb.
On May 14, 1:11 pm, payal gupta gpt.pa...@gmail.com wrote:
@atul
instead of sorting the string individually which would require tc- O(nlogn)
shouldnot it be a better idea to use the sum of the ascii values of the
Yes exactly. And now I hope to convince you that it's good to learn a
few languages so you can use the best one for the problem at hand. In
Perl for example, your proposed algorithm looks like this:
while () {
chomp;
push @{ $map{join('', sort split('', $_))} }, $_;
}
while ( (undef, $val) =
@deepikaanand:
1 is not a prime no. and also ignore 2 as chosen prime no,.
On Sun, May 13, 2012 at 6:31 PM, deepikaanand swinyanand...@gmail.comwrote:
@gaurav
the approach suggested as : to have an array of 25 prime nos..How is
it supposed to work ;
cz(this is wat i have understood) if a
11 matches
Mail list logo