Fundamental Data Structures using Java:  Linked lists and hash tables

Due: March 2, 2009

 

1. Create a new class called 'Student' which contains a student id number, a name, and a GPA. 

2. Implement a doubly linked list of Students.  A doubly linked list has two pointer fields, 'next' and 'previous', which refer to the next node and the previous node in the list respectively.   Your list must implement the following functionality:

                - addFront function to insert a new student at the front of the list.

                - addBack function to insert a new student at the back of the list.

                -  sort function to sort the students in order by GPA. (extra credit for implementing a "fast" sort). 

                - find function which takes as input a student ID number and returns the student object in the list with that ID.  The value null should be returned if no such student is in the list.

                - remove function which takes as input a student ID number and removes the student from the list.

                - updateGPA function which takes as input a student ID number and a new GPA value.  The student in the list with the given ID should have it's GPA field set to the given GPA value.

3.   The function find and update both have O(n) runtime in the worst case where n is the number of students in the list.  That is, in the worst case all n students must be looked at to find the target student.  To improve this, create a new class HashTable.  A HashTable object  should have as a data field a size H array of the linked list objects created in part 2.  The value of H will be given as a parameter to the HashTable constructor.   The HashTable class should have the following functionality: 

                - Implement a hash function which takes as input a student and computes a corresponding hash value from 0 to H-1.

                - Implement an insert function which takes as input a student X and adds X to the linked list at index value hash(X).  You may add the student to either the front or the back of the linked list.

                - Implement find, remove, and updateGPA functions for the HashTable which act in the same fashion as for the doubly linked list.

4.  Test your HashTable by inserting a large number of students ( say 500,000 ) and then repeatedly calling the find function (at least 200,000 calls to find, using different student ID's).  Test this with different hash table sizes, (H=1, H=10, H=100, H=500000).  What is the effect H has on the speed of your data structure?