I have a std::vector<std::string>
that has 43,000 dictionary words. I have about 315,000 maybe-words and for each one I need to determine if it's a valid word or not. This takes a few seconds and I need to complete the task as fast as possible.
Any ideas on the best way to complete this? Currently I iterate through on each attempt:
for (std::string word : words) {
if (!(std::find(dictionary.begin(), dictionary.end(), word) != dictionary.end())) {
// The word is not the dictionary
return false;
}
}
return true;
Is there a better way to iterate multiple times? I have a few hypothesis, such as
- Create a cache of invalid words, since the 315,000 list probably has 25% duplicates
- Only compare with words of the same length
Is there a better way to do this? I'm interested in an algorithm or idea.