Hi,

I am trying to write a program, in which it will ask the user to enter a string of length exactly 9. I have got a dictionary file with me which contains over two hundred thousand words. My job is to output all the possible words between lengths 4 to 9. For example:-

If the input word / string is LARBITNLI, then the output should be TILL, TRILL AND BRILLIANT. I have written the program but I think it is most inefficient program ever because it is taking too much time to finish. I never actually allowed to finish but since I put several print statements, I could see that it is printing out the correct possible words.

Current Algorithm

I am taking the first word of dictionary (for example:- APPLE) and then I am checking if the frequency of all 27 alphabets in APPLE is than or equal to the frequency of all 27 alphabets in LARBITNLI.

Is there any better algorithm out there ? ( definitely :-) )

Thanks

Varun

I think you're algorithm is pretty good so far:

if you're counting how much each character shows up in a word and then compare it to the ones of the other words it'll work in a good way ...

(What I also think is that this is something which can be solved in a more efficient way using the STL library)

I also found a much more inefficient algorithm than the one you're using:

I think it's way more inefficient to just try every possibility and compare it to the existing words ...

BTW, Could you post a copy of your source so we can take a look at what the 'inefficient' thing may be ...

Member Avatar for iamthwee

This shouldn't take more than a second to complete if you are using a letter frequency counter algo properly.
And because of the algorithm it should take the same amount of time to complete regardless of the length of the jumbled set of letters.

http://www.daniweb.com/code/snippet906.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.