Basically, Anagrams are like permutation of string.E.g stack
,sackt
,stakc
all are anagrams of stack
(thought above words aren't meaningful). Anyways you could have understood what I basically meant.
Now, I want a list of anagrams
given million words or simply say from a dictionary.
My basic question is Find total number of unique anagrams in a dictionary?
Sorting and comparing
won't work as it's time complexity is pretty bad.
I thought of using hash table, string as key.
But the problem is what should be the hash function ? It would be helpful if some pseudocode
provided. Some other approaches better than mentioned approaches would also be helpful.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…