Question
This is the outline for the code: i just need help filling in the methods : public class SeparateChainingHashMap { int N; LinkedList[] bucket; private
This is the outline for the code: i just need help filling in the methods :
public class SeparateChainingHashMap {
int N;
LinkedList[] bucket;
private static class Node {
private int key;
private String word;
private Node next;
Node(int key, String word) {
this.key = key;
this.word = word;
next = null;
}
}
private static class LinkedList {
int size;
Node head, tail;
LinkedList() {
size = 0;
head = tail = null;
}
public void addLast(int key, String word) {
// ...
}
public String remove(int key) {
String toReturn = null;
// ...
return toReturn;
}
}
public SeparateChainingHashMap(int N) {
// ...
}
public int calculateKey(String word) {
int key = 0;
// ...
return key;
}
public void add(String word) {
// ...
}
public boolean remove(String word) {
// ...
}
public String remove(Integer key) {
// ...
}
public String toString() {
// ...
}
}
1 Description Implement a class in Java named SeparateChainingHashMap containing the following meth ods. In our maps, we will store words made up of uppercase and lowercase English letters onljy. Consider the word string sos...Sm- of length m, then its key will be the sum of ASCII values of its letters and its final hash value (the array index where it will be stored) is given by the function: h(k)-k mod N where N is the size of the hash table and k is the key. We will use separate chaining to handle collisions. The nodes of the linked lists must have two separate fields - one for the key (integer) and one for the word (String). You should not use the linked list class already defined in the Java library 1. public SeparateChainingHashMap(int N); This constructor creates a new empty array of size N for the corresponding singly linked lists to be created after adding words to the map. 2. public int calculateKey (String word); This method returns the key of a word, not necessarily present in the map 3. public void add(String word); Adds a new word into the map by calculating its key and finally its hash value. Do not sort the nodes of a linked list. Simply, insert them at the end as they arrive else you may get different output. 4. public boolean remove(String word); This method removes the word, if it is present in the map. If present, return true else return false. 5. public String remove(Integer key); This method deletes and returns the word associated with key value key. If such an entry exists, return the word associated with the key else return null 6. public String toString ) This method returns stand this assume that N 10 and a map contains threc words Apple, Cat, Boy with keys 498, 280, 298 (think why?), rcspectively. Then System.out.println(myHashMap); where myHashMap refers to the hash map object, should print out the following 0 C288, Cat) a human readable string representation of the hash table. To under- 8 (498, Apple) -(298, Boy) Unless stated, in the programs of this course you are not allowed to use any existing Java library and/or external packages for solving the problem. You should write everything from the scratch. You will receive zero ifyourprogram does not compile or it isfound that you have copied code from some other sowrce without any reference. 2 Deliverable Upload the file SeparateChainingHashMap. java only. You are not allowed to submit any other file. Your java code should be properly indented and nicely commented. Feel free to use additional helper methods, if requiredStep 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