Anagrams are words that are composed of the same letters; for example, the words “eat,” “ate,” and “tea” are anagrams. Devise an algorithm to find all sets of anagrams in a large file of English words.

Solution

An efficient algorithm for this problem works in two stages. First, it assigns each word a "signature" obtained by sorting its letters and then sorts the file in alphabetical order of the signatures to put anagrams next to each other.

Share this thread

Comments

Comments
comments powered by Disqus

Navigation

Social Media