App Overview
In this game you append a letter to growing chain of letters, but each player tries not to form a word. You have the option to say it's a word after your opponent chose a letter to append to the chain of letters, which needs to be checked to a certain data-structure. I need to implement this data-structure.
Requirements of Data-structure
- I need a data-structure that is able to tell fast if a word exists in a list of 240000 words for a game on an android device.
- You should be able to play up to 20 games easily
- Should be written for an android app
A nice extra feature would also be to quickly show all possible words from a given word but is not necessary.
What I tried
A Radix Tree seemed like a good idea for this, see the picture below. Now I might regret the time I put into this, since I think it would require too many objects. Every black dot as well as the numbered circles would be represented as node object
s in my code.
A radix tree would require at the bare minimum 240k (240,000) nodes and thus objects, each path to every node would be one word, which would result in the 240k word list. Each game would be represented only storing a reference to the current node in the tree, meaning that an extra game requires little extra storage.
I also thought that I could implement it as a hashMap with all possible words in it and loop through all the words and narrow down after each letter. This seems like a computational approach, where the Radix Tree would require less computations but a lot more storage.
[EDIT] This was a wrong assumption of mine, look below at the picture.
Questions I have
Is a Radix Tree one of the best data-structure for the requirements given most android devices used today? (answers/comments seem to indicate it is)
How does it work in memory when you have so many objects? Are they all stored in ram or also on the disk? I could find this that an app could use a total of 16mb/25mb/32mb of ram. Is it likely I will reach over 16mb of ram when putting 240000 object in ram?
You can store and retrieve the large Radix Tree object during runtime from a file right? Which is stored to a disk in the res/raw folder.
Would having (let's say) 50 games open with a hash-map in which for every game you have to use a copy of the hashmap, on which you narrow down the possible words, be even possible? How much additional storage can an application claim after installation?
Based on the comments: It seemed like my assumption that a Radix Tree would require more space seemed wrong: To see the image larger right click on it and open in new tab