How would you go about searching if a word exist in a 4x4 Grid of random letters(A-Z).Can someone lead me into the right direction of an effective way of tackling this problem.
Here are the conditions:
- Words are formed from adjoining letter
- words can be formed horizontally, vertically or diagonally to the left, right or up-and-down
- No letter cell may be used more than once within a single word.
Thanks for your help guys!
If you are just working on a 4X4 grid, it should be quite simple. Scan for the first letter of the word and in every direction search if that word can be completed from the grid.
If the grid is very large and/or you are performing lots of searches you might want to pre-process the grid first. Eg. For every couple of characters (lets call them k-grams since in general you want to keep track of k characters) you can keep list of locations where they are located. When you are searching, first look for the location of k-grams of that word.