CS313E Assignment 10: Jumble Step 4 (10 points)

Due: by Wednesday, December 5, 2012 by 11:59pm

Your program listing should have the following information.

#  Files: Trees.py, Wordlist.py, Solver.py, README
#
#  Description:
#
#  Student's Name:
#
#  Student's UT EID:
#
#  Course Name: CS 313E 
#
#  Date Created:
#
#  Date Last Modified:

The Assignment

You can do this assignment with one other student. Only submit one version, but be sure to indicate on your submission what students participated.

This is the fourth in a series of assignments aimed at solving the Jumbles that you see in the paper or online: Jumble website. The idea is this: given a series of scrambled words, unscramble them.

The basic algorithm is as follows: given a scrambled word (e.g., ACTMH), you generate permutations of the word and check your wordlist until you either find the word (MATCH), or you exhaust the list of permutations, in which case you report failure.

You solved this problem by searching a simple unordered Wordlist in Assignment 6, a sorted list in Assignment 8, and a hash table in Assignment 9. In this assignment, you'll be building on what you did in Assignment 8. Be sure to use the code from Assignment 8, not from Assignment 9.

Feel free to update your code from Assignment 8 as you see fit. But you should have to change very little in your Solver module to make this work. You should strive to have very minimal changes to your Solver file. You really are only changing the implementation of your Wordlist class. However, for this assignment, you don't have to do any of the command line processing you did in Assignment 8, so you can remove that code.

Implement the steps below.

Extend Your Wordlist ADT

To your Wordlist class file from Assignment 8, you will add another class BinaryTreeWordList, which extends your current Wordlist class and inherits from it. The BinaryTreeWordList class should override the following methods: __init__, addWord, and findWord. If you didn't implement addWordsFromFile by repeatedly calling addWord, you may have to override addWordsFromFile also.

You __init__ function in the new class should look like this:

    def __init__(self):
        Wordlist.__init__( self )
        self._wordtree = Trees.BinarySearchTree()
That is, you're adding a new data item, which is a BinarySearchTree. It should have available all of the functions on a binary search tree.

You will build your wordlist by inserting each word (of the correct length) into the binary search tree Method findWord should search for the presence of a string in the tree using the inTree method from the BinarySearchTree class. You can return the number of comparisons for each search using the nodeDepth method from the BinarySearchTree class.

The interface for BinaryTreeWordList should be exactly the same as the interface for WordList. That is, the user of the class should not see any difference.

Write a Top-Level Driver

Your main program should construct the wordlist as an instance of the BinaryTreeWordlist class. You can remove the command line argument stuff from Assignment 8 (or keep it if you like).

Then, populate your wordlist (tree) as before with the words from file: Unordered word list, filtering to store only words of 5 or 6 letters. As in earlier assignments, print out the number of words in the wordlist and how long it took to generate the wordlist.

Following that initial setup, your main program should do exactly what it did in earlier assignments: Enter a loop and in each iteration prompt the user for an input string, generate permutations of the string, and test whether any permutation is in the wordlist. If so, return that word as your answer along with statistics of the search (how many comparisons you made, how many permutations were tried, and how long it took). If no permutation is in the wordlist, report failure and the statistics of the search. Loop until the user enters "exit." User input should not be case sensitive. The output should be very nearly identical to that from Assignment 6.

Compare the Four Implementations

Take the README file you produced for Assignment 9 and extend it to add the comparison of this latest method. That is, run your new program with the same data as the previous three runs, and indicate in your new README file how the new method compares to the previous results. Explain the differences you see.

Sample Output

felix:> python Solver.py tree
Using binary tree wordlist.
Creating wordlist

The Wordlist contains  22633  words.
Building the Wordlist took 1.741 seconds

Enter a scrambled word (or EXIT):  seyzt
Found  120 permutations;  120.0 unique permutations
Found word: zesty
Solving this jumble took 0.00590 seconds
Checked  48  permutations.
Made  776  comparisons.

Enter a scrambled word (or EXIT):  chitk
Found  120 permutations;  120.0 unique permutations
Found word: thick
Solving this jumble took 0.00459 seconds
Checked  29  permutations.
Made  636  comparisons.

Enter a scrambled word (or EXIT):  daciev
Found  720 permutations;  720.0 unique permutations
Found word: advice
Solving this jumble took 0.08427 seconds
Checked  542  permutations.
Made  10759  comparisons.

Enter a scrambled word (or EXIT):  nimleg
Found  720 permutations;  720.0 unique permutations
Found word: mingle
Solving this jumble took 0.07916 seconds
Checked  489  permutations.
Made  10596  comparisons.

Enter a scrambled word (or EXIT):  torll
Found  120 permutations;  60.0 unique permutations
Found word: troll
Solving this jumble took 0.00105 seconds
Checked  6  permutations.
Made  124  comparisons.

Enter a scrambled word (or EXIT):  exit
Thanks for playing!  Goodbye.
felix:~/cs313e/python/newjumble>