YCP Logo Assignment 4: Boggle(tm) Solver

Due: Friday, Feb 26th by 11:59 PM

Acknowledgment: the dictionary files are taken from an assignment by Julie Zelenski, Paul Kube, Owen Astrachan, and Jeffrey R.N. Forbes. (I thought of the idea for the assignment on my own, but obviously the idea has occurred to other people, too :-)

Getting Started

Download CS350_Assign4.zip. Import it into your Eclipse workspace (File->Import...->General->Existing projects into workspace->Archive File). You will see a project called CS350_Assign4 in the Package Explorer.

Do not use java.util

In this course, you are required to implement all data structures from scratch. Do not use any of the classes in the java.util package.

Exception: You may use java.util.StringTokenizer.

Do not copy code from textbook or other sources

Some assignments in this course may involve data structures which are implemented by source code in the textbook. And, of course, lots of code is available from web sites and other sources.

I expect you to implement all data structures and algorithms from scratch, using your knowledge of how they work. Do not copy code from any source, including the textbook.

Exception: You may use any code explicitly posted on the course web site.

Your Task

Your task is to write a program that automatically finds all words in a given dictionary that can be found on a Boggle(tm) grid.

A Boggle grid is a 4x4 grid, where each grid cell contains a single letter or the pair "Qu". A Boggle grid contains a word if it is possible to start at one cell of the grid and move to a sequence of 1 or more additional grid cells so that the letters in the word correspond exactly to the letters on the sequence of grid cells visited.

When moving from one cell to the next, it is legal to move to any of the 8 immediately surrounding grid cells. However, it is not legal to visit a grid cell which has been visited previously. (In other words, a sequence of cells may not revisit the same cell twice.)

Example: consider the following grid:


The word "SEQUINS" can be found using the following path (starting at the cell outlined in blue and continuing along the path indicated by the red arrows):



The following classes are provided:

BoggleGrid - represents a boggle grid

BoggleGridFactory - creates random boggle grids

BoggleSolutionCollector - interface implemented by objects which collect words found in a BoggleGrid.

BoggleSolver - using a given dictionary, find all words in a given BoggleGrid. (The dictionary determines which sequences correspond to words.)

Each class has Javadoc comments describing the purpose of the class and its methods. You can browse the javadoc.

Your task is to implement the methods in the BoggleSolver class: specifically, the readDictionary and solve methods.

Running the program

To run the program, right-click on the BoggleSolver class and choose Run As->Java Application.

You will need to enter the name of a dictionary file. Two are provided:

  • bogwords.txt - a basic dictionary
  • enable1.txt - a much more extensive dictionary containing lots of obscure words

Example run (user input in bold):

Dictionary file: bogwords.txt
Grid is:
  E  R  P  B
  D  O  C  D
  L  L  E  A
  R  E  U  F

lots of other words omitted...
The solver found 67 solution(s).

Hints / Approach

Use a trie to represent the dictionary.

You will need to think carefully about how to find all of the sequences corresponding to words in the dictionary. The general idea is to have the algorithm, as it progresses, keep track of all of the partial sequences found so far that either

  • are words, or
  • could be words with some additional letters appended

Each partial sequence should record

  • which grid cells have been visited, and
  • the trie node representing the sequence

The algorithm is initially seeded with the one-letter sequences corresponding to each grid cell. These represent the possible first letters of words that could appear in the grid.

At each step of the algorithm, an in-progress sequence is chosen an evaluated as follows:

  • if the sequence is a word, report it to the BoggleSolutionCollector
  • try to extend the sequence by moving to all adjacent cells which have not been visited by the sequence; this may produce new "continuation" sequences which are one letter longer than the current sequence

Because each partial sequence can be extended into up to 8 continuation sequences, you will need to use a data structure to keep track of all of the partial sequences which are still "alive". Either a stack or a queue is a reasonable choice. A stack will give you a depth-first search of the solution space, while a queue will give you a breadth-first search.

You should use the trie to immediately weed out partial sequences that cannot possibly be the beginning of any word in the dictionary.


Your grade will be determined as follows:

  • Dictionary is read: 10%
  • Dictionary is stored in an appropriate data structure (i.e., trie): 25%
  • Seeding of search algorithm: 15%
  • Progress of algorithm, reporting of solutions: 50%
  • Correct handling of "Qu": 5% [bonus credit]

Points may be deducted for poor coding style.


Export your finished project to a zip file (right-click on the project, then Export...->Archive File). Upload the zip file to the marmoset server as project assign4. The server URL is


IMPORTANT: after uploading, you should download a copy of your submission and double-check it to make sure that it contains the correct files. You are responsible for making sure your submission is correct. You may receive a grade of 0 for an incorrectly submitted assignment.