Advise on efficiency of solution of Anagrams and related problems

Back to General discussions forum

Mandeep_Verma     2016-03-27 12:11:05
User avatar

To solve the anagrams problem I gave each letter a prime numbered value (a=2,b=3,c=5..) and multiplied the values of each letter present in a word to create a certain "score" of each word in the dictionary and stored it in another file. Which was something on the lines of:

510312824 aardvark 34190959208 aardvarks 1380 abaci 1860 aback 293460 abacus 216280020 abacuses

It might not be as fast as the approach to sort letters of each word for anagrams but when solving a problem such as the problem "four pics one word" on the site itself, I just had to do a divisbilty check and not worry about creating all possible combinations. I wanted to know if this approach is any good. A comparison of complexity, time and memory would be appreciated.

P.S. The "score" has to be calculated via BigIntegers so it may have problem in some languages. Thank you in advance :).

Please login and solve 5 problems to be able to post at forum