Hi all,

I have givn a task to implement a game.
It has ruls of texa's Holdem poker and the objective is to
make words like scabble.So it is a blend of these 2 games.

So i need to store (Only with 5 letters)words(I dont know whether it is a trie,database,map or what..).
There are about 20,000 words.
What i want do is:
When im providing 2 letters(ex: a,c) the storage should give me all the words
which contains a and c.

PLZ some one give me a way of doing this.
I feel like store all the words in a text file and retrieve word by word and use regular expresssion.
Will it be good in performance wice?
Or give me a better idea of doing this.

PLZ HELP..
Thnx in advance.

Recommended Answers

All 4 Replies

For that size of data there's no reason why you would not keep it all in memory - about a megabyte should be enough. You can simply read a text file with all the words into an array of Strings. Searching in memory will be orders of magnitude faster than searching a file, and a lot easier as well.
Looping through 20,000 strings testing for particular characters shouldn't take too long relative to human timescales, but it would be a good idea to define a method that just does the searching so that it's easy to try different solutions to implement the method without needing to change any other parts of the program (eg regex vs checking the characters with simple if tests vs clever indexing schemes).

Thanx.
I'll implement it that way.
Thanx 1ce again

The requirements for the project was changed. Now I have 51947 words.

And i want get all the words when i provide a set of letters.
Ex: abanana
answers: BANANA ANNA NAN NANA ABA ANA ...

Is it still ok to load the words into an array and do this search.
Or is it better to implement a trie?

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.