Implement a generic graph class using an adjacency list to store the edges. Include DFS and BFS methods. Your textbook gives the pseudocode. Test your class on a number of randomly generated graphs (e.g. 5-10 nodes). The choice of data structures will be discussed in class. Be sure to include a toString method that prints out the graph's edgelist.
Word Game There is a word game where player 1 begins by writing down a 5 letter word. Player 2 must find another word that differs from the first word by one character. Player 1 then tries to find a word that differs from Player 2's word by one characer, and so forth. The game ends when a player can't think of a word to add to the sequence. A possible word sequence would be
In this lab, you will not be implementing this game but you will be investigating how to generate word sequences like the one above.
Do the following:
Create a graph (using your above code) to represent the 5 letter words in the file words5.txt. If you don't remember how to read in an ascii file, go back to your "spell checker" lab from Data Structures.
Creating the graph should be really easy if you implemented the graph class correctly! Each node in the graph will be a word (i.e. String). An edge connects two words if the words differ by exactly one character. Have the computer randomly select a starting word W and generate the DFS and the BFS trees starting at that node. What do these trees tell you?
Now, write a method that will print out the longest possible word sequence assuming you are starting with W (how do you do this?).
Thought question (don't implement!): How would you use the information in your word graph to implement a minimax game tree for the above game assuming a player was playing against the computer?
The file words5.txt contains only 183 words. The algorithm slows can down significantly (if you aren't careful) when the number of words increases. The file words5long.txt contains 6951 words. Does your program still run? If not, figure out where the problem is and fix it.
Deliverables: Be prepared to demo in class or lab. Please add javadoc comments to the code. Zip together project and email code to gorr. Please be sure to put CS343 Word Game in the subject line.