In this homework we will build an inverse word search program using the techniques of recursion. The goal is to construct a grid of letters that one can search to find specific words. Understanding the non-linear word search program from Lectures 13 & 14 will be helpful in thinking about how you will solve this problem. We strongly urge you to study and play with that program, including tracing through its behavior using a debugger or cout statements or both. Please read the entire handout before beginning your implementation.

Your Tasks

For this assignment, you will be given the dimensions (width and height) of a word search puzzle, a set of words that should appear in the grid (forwards, backwards, up, down, or along any diagonal), and optionally a set of words that should not appear anywhere in the grid. Each grid cell will be assigned one of the 26 lowercase letters. Note that unlike the non-linear word search problem we discussed in class, we will only allow words that appear in a straight line (including diagonals). Your task is to output all unique word search grids that satisfy the requirements. Rotations and mirroring of the board will be considered unique solutions.

Your program should expect three command line arguments, the name of the input file, the name of the output file, and a string:

inverse_word_search.exe puzzle2.txt out2.txt one_solution
inverse_word_search.exe puzzle2.txt out2.txt all_solutions

The third argument indicates whether the program should find all solutions, or just one solution. Heres an example of the input file format:

4 4
+ arts
+ arid
+ east
+ rest
- ear
- at
- sit

Figure 1. see image.

The first line specifies the width and height of the grid. Then each line that follows contains a character and a word. If the character is +, then the word must appear in the grid. If the character is -, then the word must not appear in the grid. For this first example we show an incorrect solution on the left. Though it contains the 4 required words, it also contains two of the forbidden words. The solution on the right is a fully correct solution. This particular problem has 8 solutions including rotations and reflections.

Below is a second example that specifies only positive (required) words. This puzzle has 4 solutions including rotations and reflections.

5 3
+ echo
+ baker
+ apt
+ toe
+ ore
+ eat
+ cap

Figure 2. see image.

When asked to find all solutions, your program should first output the number of solutions and then an ASCII representation for each solution. See the example output on the course webpage. You should follow this output closely, however your solutions may be listed in a different order. When asked to find just one solution, your program should just output the first legal solution it finds (it does not need to count the number of solutions). If the puzzle is impossible your program should output No solutions found.

To implement this assignment, you must use recursion in your search. First you should tackle the problem of finding and outputting one legal solution to the puzzle (if one exists). Nearly full credit will be given for submissions that do this correctly. Full credit will be given to programs that find all of the solutions.

Algorithm Analysis

For larger, more complex examples, this is a really hard problem. Your program should be able to handle the small puzzles we have created in a reasonable about of time. You should make up your own test cases as well to understand this complexity. Include these test cases with your submission (they will be graded). Summarize the results of your testing, which test cases completed successfully and the approximate wall clock time for completion of each test. The UNIX/cygwin time command can be prepended to your command line to estimate the running time:

time inverse_word_search.exe puzzle1.txt out1.txt

Once you have finished your implementation and testing, analyze the performance of your algorithm using order notation. What important variables control the complexity of a particular problem? The width & height of the grid (w and h), the number of required words (r), the number of forbidden words (f), the number of letters in each word (l), the number of solutions (s)? In your plain text README.txt file, write a concise paragraph (< 200 words) justifying your answer. Also include a simple table summarizing the running time and number of solutions found by your program on each of the provided examples. Note: Its ok if your program cant solve the biggest puzzles in a reasonable amount of time.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.