Answered step by step
Verified Expert Solution
Question
1 Approved Answer
part 1 & 2 thank you PART I: HashPair 1) We will store the key and data in the Hash Table. Also, instead of having
part 1 & 2
thank you
PART I: HashPair 1) We will store the key and data in the Hash Table. 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. If o 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 insert(HashPair item); /ot in book, replace value if same key b. abstract boolean remove(Object key); //changed from book c. 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 tempStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started