What is an easy way to tell if a list of words are anagrams of each other?

Put all the letters in alphabetical order in the string (sorting algorithm) and then compare the resulting string.


Good thing we all live in the C# reality of in-place sorting of short words on quad core machines with oozles of memory. :-)

However, if you happen to be memory constrained and can't touch the original data and you know that those words contain characters from the lower half of the ASCII table, you could go for a different algorithm that counts the occurrence of each letter in each word instead of sorting.

You could also opt for that algorithm if you want to do it in O(N) and don't care about the memory usage (a counter for each Unicode char can be quite expensive).


Sort each element (removing whitespace) and compare against the previous. If they are all the same, they're all anagrams.