Outcomes Addressed

Procedure

You should write a program that will analyze the impact of varying the load factor of the HashSet when used to store the dictionary file used in Lab 4.

Your program should generate all of the results for the following table:

Load Factor # of collisions # of empty buckets Maximum # of elements in a bucket
0.25   
0.50   
0.75   
0.99   

You should assume that the capacity of the HashSet is doubled whenever the load factor is exceeded.

Relevant tidbit

You will not be able to use the HashSet to do your tests. You should use either an array or an ArrayList instead.

String.hashCode Overwriting

Create four new classes that contain a String as a field and override the hashCode() method. For each new class, generate another table similar to the one above. Your revised hashCode() methods should calculate the hash code as follows:

  1. The hash code is equal to the length of the string.
  2. The hash code is equal to a random long between zero and four million.
  3. The hash code is equal to ASCII value of the first character multiplied by 32 plus the second character multiplied by 32 times 2 plus the third character multiplied by 32 times 3, etc...
  4. Some algorithm of your choosing.

Although the XML template file includes the tables, you may find it easier to programmatically generate the tables and then paste the program output into your report.

Lab report (due at 4pm, Friday of week 10)

Here is a template file to use as a starting point for this report.

Your report should include:

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the XML help video and/or sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost.

If you have any questions, consult your instructor.

Acknowledgment

This assignment was originally developed by Dr. Chris Taylor.