CSC 103 Assignment 3:
Hashing




Due Date

10PM Wednesday 16 May 2001

Program Specification, Part A -- Basic Lookup Table

Define a class named LookupTable with the following methods:

  1. a constructor with no parameters, that constructs an empty table;
  2. a constructor with an integer size parameter, that specifies the initial number of entries in the table;
  3. an enter method that takes a LookupTableEntry and enters it in the table, including entries with duplicate keys but otherwise unequal; the updated table is returned;
  4. a lookup method that takes an Object key and returns an array of LookupTableEntrys, containing the zero or more entries that have the same key as the input key;
  5. a delete method that takes an Object key and removes all entries that have the same key as input key; the (possibly) updated table is returned;
  6. a toString method that converts the table into a newline-delimited string of the form
        Entry 0: value
        ...
        Entry size-1: value
    

To support this class, define an interface LookupTableEntry, that has the same two methods as the example HashTableEntry, plus a getNext method that returns the next node in a chain of LookupTableEntrys.

The implementation requirements are the following:

  1. collision resolution is by out-of-table chaining;
  2. entries of duplicate keys are allowed, as long as the entries differ in at least one other field; i.e., two entries e1 and e2 of the same key value can be put in the table, as long it's NOT the case that e1.equals(e2)
  3. when the table reaches a load factor of 0.8, the table size is doubled by two times

Program Specification Part B -- Lookup Table with Secondary Key

Add the following methods to the LookupTable implementation of part A:

  1. an enter2 method that has the same specification as enter, but works with the secondary key of the given entry
  2. a lookup2 method that has the same specification as lookup, but uses the secondary key for searching
  3. a delete2 method that has the same specification as delete, but uses the secondary key for deletion

To support this class, define a subinterface of LookupTableEntry named LookupTableEntry2; LookupTableEntry2 adds two methods named getKey2() and hash2, for retrieving and hashing the secondary key of the entry

IMPORTANT: for part B, change all references in the part A implementation of of LookupTable from LookupTableEntry to LookupTableEntry2.

Program Specification Part C -- Lookup Table with Sort Method

To the implementation of part B, add a sort method that returns a sorted array of LookupTableEntry2s, in ascending order by primary key.

Analysis for Part

For part A, define the analytic timing function for LookupTable.lookup, as discussed in Lecture Notes Week 6.

For part B, define the analytic timing function for LookupTable.resize, where resize is the name of the method that performs the table resizing when the load factor reaches 0.8.

For part C, define the analytic timing function for LookupTable.sort.

Documentation for All Parts of the Assignment

Provide class header, method, and inline documentation comments, using the javadoc standards illustrated in the 103 example programs.

Grading

There is a three-tier grading scheme for this assignment. If you're satisfied with no better than a "B" grade (i.e., 80%), do part A only. If you'd like the lowest possible "A" (i.e., 90%), do parts A and B. If you'd like to go for 100%, do parts all three parts A, B, and C.

Turnin

Turn in one plain text file named analysis that contains all three parts of the analysis. Clearly label each of the parts A, B, and C (or as many of them as you do).

If you attempt part A only, turnin LookupTable.java and LookupTableEntry.java. If you attempt parts B and/or C, turnin LookupTable.java and LookupTableEntry2.java.