I am implementing a text-based version of Scrabble for a College project.
My dictionary is quite large, weighing in at around 400.000 words (std::string).
Searching for a valid word will suck, big time, in terms of efficiency if I go for a vector<string> ( O(n) ). Are there any good alternatives? Keep in mind, I’m enrolled in freshman year. Nothing TOO complex!
Thanks for your time!
Francisco
If you wanted to go for something that is in the standard library, you could use
std::setwith the word as the key. That would give you logarithmic search time.Since your dictionary is presumably static (i.e. created once and not modified), you could also use a
std::vector, sort it usingstd::sort, and then usestd::binary_searchon the sorted vector to find a word. This would also give logarithmic search time, and would possibly be more space efficient than aset.If you want to implement your own data structure, a trie would be a good choice.