c# - Finding the set of words that can be spelled with a given set of letters -


The problem is facing to create an efficient algorithm that gives a list of words from a certain word list Spelling, using the letter (this set input) is not upper bound with this set (or at least none useful).

More specifically, this algorithm needs to provide solutions in real time for a continuous growth input, although the output can gradually get out, because the first few output elements are relatively Come out quickly.

** Note: The actual increase in input is only in the form of adding an existing set when a word is chosen, then the letterstock is used to end all the letters and the algorithm starts again. .

The possible letter sets are 26 standard Roman letters. Stock of each letter is 0- & gt; It can be anywhere from infinity (for all intense purposes) and each letter can be used only once (like A, B, L "ball" will not return, although A, BB, D, LLL) Working with the word list is continuous, so if any pre-computing hashing solution would be useful to speed runtime performance, then this is an option (although I can not think of a good method this). However, the word list is large (~ 40,000 elements).

So far, the best algorithm I have created is through a letter using letters and using a copy of each letter and checking each word. Letter, per share By decreasing and if any letter is below 0, then seeing it. If this happens, then I go ahead, and if I reach the end of the word, then I add words to the solution set. After going through the entire set, I search for words from the beginning that I can now spell that 1 or more letters have been added to my letterstock.

  A copy of the string and letterstock can be billed to the 26-entry array (string str, int * letterstock) {for (int i = 0; i & lt; str.length; i ++) {letterStock [str [i] -65] -; // Finish the letter share for the given letter if (letter stoke [str [i] -65] <0) return false; } Back true; }   

My question is as follows: Is this implementation favorable and if not, what's better?

A little out of the box, but did you use something like Word for memory / query SQL is? Can solve all your problems

Comments