Android Question Tries Data Structure ?

paris7162

Member
Licensed User
Longtime User
Is there an easy way to find all of the possible words in a 5 x 5 letter matrix? The matrix would be similar to the Boggle Game, however, in this letter matrix the letters can repeat.
 

mc73

Well-Known Member
Licensed User
Longtime User
I would do it step-by-step concerning lengths. First, scan for 2 letters. Query a 'like %yourLetters%' with their both combinations, then if count>0, you have two things: a) there exist count(*) words (1 or 2) and b) you will proceed with scanning for the third letter, which in the matrix can be from the neighborhood of the first letter (the second will be scanned in the next iteration). Then with 4th letter and so on.
a11 a12 .. a15
a21 a22 .. a25
. .
. . .. .
. . ...

Take a11,a12. Check both combinations (a11,a12) and (a12,a11). If found, grab the 3rd letter, a21 and a22, and get the combination working from the previous test, and recreate adding a21 and a22 (not together).
Again count results, then go on with for example (a11,a21,a31) and so on...
 
Upvote 0

paris7162

Member
Licensed User
Longtime User
Thanks Guys, you are great as always! I love this forum.

I'm sure I'll have more questions about this once I start. I just thought someone would have some code already created to make my life a little easier.
 
Upvote 0
Top