Question: SUBMISSION 1. CREATE a class that is your last name, place code in TestHash in it, and place the classes HashPair, Hash, LinearHash, ChainHash, DLNode,






SUBMISSION 1. CREATE a class that is your last name, place code in TestHash in it, and place the classes HashPair, Hash, LinearHash, ChainHash, DLNode, DLList as static classes inside the last-name class. 2. CREATE a PDF file containing your output DIRECTION Create Java classes to implement Hash Table with Chaining and Linear Probing, and a program to test them. This project will require more thinking regarding what classes are required, and what methods are in the classes. PART I: HashPair 1) [Different from zyBook] Instead of just storing the key in the hash table, we will store data associated with the key. Also, instead of having only int keys, zyBooks gives the ability to have String keys. So we need the class HashPair with two fields: Object key; Object value; 2) Create a toString method that returns (key,value) Example: (81,214) 3) Create a public boolean equals(Object o) method that allows comparing against HashPairs and just keys, by doing the following: a. Ifo is a HashPair, returns this.key equals o.key b. Ifo is not a HashPair, returns this.key equals o PART II: Hash abstract class 1) Since we are implementing two types of hash tables (chaining and linear probing), it makes sense to create a superclass of the two types. And since the superclass does not have its insert and remove clearly defined, we create public abstract class Hash. This has the following abstract methods: a. abstract boolean insertBook(HashPair item); b. abstract boolean insert(HashPair item); /ot in book, replace value if same key c. abstract boolean remove(Object key); //changed from book d. abstract HashPair search(Object key); 2) Despite being an abstract class, Hash has methods that are in common for all its subclasses. These will be concrete methods associated with the hash function. Since we want to have both Chaining and Linear Probing use the same hash function, we can put the modulo hash function inside the class Hash. a. Implement static int pMod(int i, int N) that takes the positive modulus. Basically, store i % N inside temp, if temp [(91,208)]->X} Chaining Hash Initial Hash Table {0:X) {1:X) {2:X) {3:X) {4:X) {5:X) {6:X) {7:X) {8:X) {9:X) Insertion Test Insert (13,380): {0:X) {1:X) {2:X} {3:XX} {4:X) {5:X) {6:X) {7:X) {8:X) {9:X) Insert (43,290): {0:X) {1:X) {2:X) {3:X [ (43,290)]->X} {4:X} {5:X) {6:X) {7:X) {8:X) {9:X) Insert (46,456): {0:X) {1:X) {2:X) {3:X [ (43,290)]->X} {4:X) {5:X) {6:XX} 17:X) SUBMISSION 1. CREATE a class that is your last name, place code in TestHash in it, and place the classes HashPair, Hash, LinearHash, ChainHash, DLNode, DLList as static classes inside the last-name class. 2. CREATE a PDF file containing your output DIRECTION Create Java classes to implement Hash Table with Chaining and Linear Probing, and a program to test them. This project will require more thinking regarding what classes are required, and what methods are in the classes. PART I: HashPair 1) [Different from zyBook] Instead of just storing the key in the hash table, we will store data associated with the key. Also, instead of having only int keys, zyBooks gives the ability to have String keys. So we need the class HashPair with two fields: Object key; Object value; 2) Create a toString method that returns (key,value) Example: (81,214) 3) Create a public boolean equals(Object o) method that allows comparing against HashPairs and just keys, by doing the following: a. Ifo is a HashPair, returns this.key equals o.key b. Ifo is not a HashPair, returns this.key equals o PART II: Hash abstract class 1) Since we are implementing two types of hash tables (chaining and linear probing), it makes sense to create a superclass of the two types. And since the superclass does not have its insert and remove clearly defined, we create public abstract class Hash. This has the following abstract methods: a. abstract boolean insertBook(HashPair item); b. abstract boolean insert(HashPair item); /ot in book, replace value if same key c. abstract boolean remove(Object key); //changed from book d. abstract HashPair search(Object key); 2) Despite being an abstract class, Hash has methods that are in common for all its subclasses. These will be concrete methods associated with the hash function. Since we want to have both Chaining and Linear Probing use the same hash function, we can put the modulo hash function inside the class Hash. a. Implement static int pMod(int i, int N) that takes the positive modulus. Basically, store i % N inside temp, if temp [(91,208)]->X} Chaining Hash Initial Hash Table {0:X) {1:X) {2:X) {3:X) {4:X) {5:X) {6:X) {7:X) {8:X) {9:X) Insertion Test Insert (13,380): {0:X) {1:X) {2:X} {3:XX} {4:X) {5:X) {6:X) {7:X) {8:X) {9:X) Insert (43,290): {0:X) {1:X) {2:X) {3:X [ (43,290)]->X} {4:X} {5:X) {6:X) {7:X) {8:X) {9:X) Insert (46,456): {0:X) {1:X) {2:X) {3:X [ (43,290)]->X} {4:X) {5:X) {6:XX} 17:X)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
