Question: This program is supposed to find all the words in a boggle grid using a normal dictionary file and limiting it to only words of
This program is supposed to find all the words in a boggle grid using a normal dictionary file and limiting it to only words of 3 or higher length to be found. It works for the most part but for some reason only some of the words are found not all. For example in this 4x4 grid it only finds 148 out of 191.
4 qu e a i n e r e t w s t o r k y
These are the words it finds:

and it should find these:
\
I dont know how to fix this. Here is my program:
import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner;
//please make sure you have dict.txt containing mentioned dict in the same directory from where you are executing code
public class Project10 { private static Map
// If str is present in dictionary, then print it if (isWord(str)) { if (!foundWordList.contains(str)) foundWordList.add(str); //System.out.println(str); } int M = board.length; int N = board[0].length; // Traverse 8 adjacent cells of boggle[i][j] for (int row=i-1; row=0 && col>=0 && !visited[row][col]) findWordsUtil(board,visited, row, col, str); } }
// Erase current character from string and mark visited // of current cell as false if (str != null && str.length() > 0 ) { str = str.substring(0, str.length()-1); } visited[i][j] = false; } // Prints all words present in dictionary. public static void findWords(String board[][]) { int M = board.length; int N = board[0].length; // Mark all characters as not visited boolean visited[][] = new boolean[M][N];
// Initialize current string String str = "";
// Consider every character and look for all words // starting with this character for (int i=0; i findWords(board); Collections.sort(foundWordList); for(String word : foundWordList) System.out.println(word); } } and this is the dictionary file to use in the code: http://people.cs.pitt.edu/~hoffmant/S17-401/project-10/dictionary.txt
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
