Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
University of Wisconsin – Parkside Department of Computer Science Prof. Dr. F. Seutter Fall 2008 Data Structures and Algorithms (CSCI 340) Programming Assignments 2. Hash Tables and Array Doubling Due Date: Friday, October 17 Points: 10 A dictionary ADT is very usefull for recording names so that a program can determine when it has seen a name before and when it is seeing a name for the first time. For example, compilers need to keep track of what names have occured, or a data base needs a fast access to data via names. A technique for implementing a dictionary ADT often is hashing. Implement a dictionary ADT for names by a hash table with open addressing based on an array data type. Do not use the class Hashtable from the Java API. Names have to be inserted into, retrieved and deleted from the dictionary. For simplicity, there is no more data stored with the names. A name is a nonempty string of letters. Define a hash function which spreads the names around fairly uniformly. Do not use method hashCode of class String from the Java API. The hash table initially has size 16. Its size is to double whenever becoming too full and halved whenever becoming too empty. Assume a load factor between .3 and .7 appropriate. Additionally, some statistical statements about the hash table shall be implemented. Support the following operations: • boolean Member(Dict d, String name) Returns true, if name is member of d, otherwise retruns false. • int Retrieve(Dict d, String name) Returns the hash code of name, if name is member of d, otherwise returns −1. • void Insert(Dict d, String name) Stores name in d, if it is not already in, otherwise does nothing. • void Delete(Dict d, String name) Deletes name in d, if it is in, otherwise does nothing. • int Collisions(Dict d) Returns the average number of collisions accessing all names in the hash table. • void ExpandTable(Dict d) Expands the hash table d by doubling the array size. 1 • void ShrinkTable(Dict d) Shrinks the hash table d by halving the array size. This list is not exhaustive. Some more operations will be needed. For example, the hash code of a name must be computed to insert or access it, or for testing your implementation a complete output of the hash table’s content in a text file would be helpfull. Embed your implemetation of a dictionary ADT in a test program (console application). Name the class containing the main method HashMain. Run your program with given test data of names. All mentioned files will be found via my homepage. (a) Insert the names of file names1.txt. (b) Delete the names of file names3.txt. After the processing of each file output the table size, number of entries, number of logically deleted entries, load factor, and average number of collisions accessing all names. Interpret these numbers relating to the quality of your hash function. What to Submit: • All *.java and *.class files of this project. • A file ReadMe.txt with a description how to compile, run, and use your application. I will test your application with the Java SE Development Kit (JDK 1.6.0-03) from the command-line. So be sure the command javac compiles your source files and the command java executes your applications without loading additional resources. • Documentation of your implementation, including the definition of the hash and rehash function, generated by the javadoc utility. So, your program must contain adequate comments of the form “/ ∗ ∗ . . . ∗ /”. • Output of the runs on the given test data with your interpretation relating the quality of your hash function (file typ .pdf). Submit all your files via e-mail. 2