Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have had quite a bit of trouble with this assignment for the past 11 days now.

ID: 3760795 • Letter: I

Question

I have had quite a bit of trouble with this assignment for the past 11 days now. I am very desperate to get this done (but with a toddler and infant around, nothing is ever easy haha). Here is the assignment. For this assignment you will create a class for counting occurrences of Strings. Effectively, this will be a hashmap from String to int. Do not use java.util.HashMap. This requires you to do some analysis. This should appear in a plain text or PDF file - no Word documents or Excel files allowed.
The StringCounter Use the following class as a starting point for yours. Note that you are using the separate chaining collision resolution strategy, with a fixed table size - no rehashing is required. When you construct a new StringCounter you specify the table size and an object to use for hashing the strings. Update: Note the chicanery required to construct an array of generic classes.
public class StringCounter {
public interface HashFunction { int hash(String key); } private class Pair { public String key; public int count; }
private LinkedList<Pair>[] buckets; private HashFunction hasher;
@SuppressWarnings("unchecked") public StringCounter(int tableSize, HashFunction hasher) { buckets = (LinkedList<Pair>[]) new LinkedList<?>[tableSize]; this.hasher = hasher; }
public void increment(String word) {
}
public int getCount(String word) {
}
public void printStatistics() {
} public String mostCommonWord() { } }

Here is a template of the separate chaining resolution strategy that is supposed to be used.
SEPERATE CHAINING RESOLUTION STRATEGY
public class SeparateChainingHashTable<AnyType> { public SeparateChainingHashTable() { This (DEFAULT_TABLE_SIZE); } public SeparateChainingHashTable(int size) { theLists = new LinkedList[nextPrime (size)]; for (int i = 0; i < theLists.length; i++) { theLists[i] = new LinkedLists<>(); } } public void insert(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; if (!whichList.contains (x)) { whichList.add(x); } } public void remove(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; if (whichList.contains (x)) { whichList.remove(x); currentSize--; } } public boolean contains(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; return whichList.contains(x); } public void makeEmpty() { for(int i = 0; I < theLists.length; i++) { theLists[i].clear(); } currentSize = 0; } private static final int DEFAULT_TABLE_SIZE = 101; private List<AnyType>[] theLists; private int currentSize;    private int myhash(AnyType x) { int hashVal = x.hashCode(); hashVal %= theLists.length; if(hashVal < 0) { hashVal += theLists.length; } return hashVal; } private static int nextPrime(int n) { } private static boolean isPrime(int n) { } }
Instructions
Write a program that uses this StringCounter to process all words in the provided words file (this file is a spell checking dictionary for unix systems), and calls the printStatistics() method to print out the following pieces of information:
1. total number of buckets 2. number of used and unused buckets 3. average size of non-empty buckets 4. maximum bucket size
Using a table size of 235886, run this program 3 times, with the 3 different hash functions as listed here. For each, collect the output of printStatistics():
1. Sum of ascii values of each String character 2. The horner’s rule-based hash function for English words (the one with the 37 in it). 3. A hash function of your own design.
Describe your results. Which is best? How did your hash function work? I have had quite a bit of trouble with this assignment for the past 11 days now. I am very desperate to get this done (but with a toddler and infant around, nothing is ever easy haha). Here is the assignment. For this assignment you will create a class for counting occurrences of Strings. Effectively, this will be a hashmap from String to int. Do not use java.util.HashMap. This requires you to do some analysis. This should appear in a plain text or PDF file - no Word documents or Excel files allowed.
The StringCounter Use the following class as a starting point for yours. Note that you are using the separate chaining collision resolution strategy, with a fixed table size - no rehashing is required. When you construct a new StringCounter you specify the table size and an object to use for hashing the strings. Update: Note the chicanery required to construct an array of generic classes.
public class StringCounter {
public interface HashFunction { int hash(String key); } private class Pair { public String key; public int count; }
private LinkedList<Pair>[] buckets; private HashFunction hasher;
@SuppressWarnings("unchecked") public StringCounter(int tableSize, HashFunction hasher) { buckets = (LinkedList<Pair>[]) new LinkedList<?>[tableSize]; this.hasher = hasher; }
public void increment(String word) {
}
public int getCount(String word) {
}
public void printStatistics() {
} public String mostCommonWord() { } }

Here is a template of the separate chaining resolution strategy that is supposed to be used.
SEPERATE CHAINING RESOLUTION STRATEGY
public class SeparateChainingHashTable<AnyType> { public SeparateChainingHashTable() { This (DEFAULT_TABLE_SIZE); } public SeparateChainingHashTable(int size) { theLists = new LinkedList[nextPrime (size)]; for (int i = 0; i < theLists.length; i++) { theLists[i] = new LinkedLists<>(); } } public void insert(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; if (!whichList.contains (x)) { whichList.add(x); } } public void remove(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; if (whichList.contains (x)) { whichList.remove(x); currentSize--; } } public boolean contains(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; return whichList.contains(x); } public void makeEmpty() { for(int i = 0; I < theLists.length; i++) { theLists[i].clear(); } currentSize = 0; } private static final int DEFAULT_TABLE_SIZE = 101; private List<AnyType>[] theLists; private int currentSize;    private int myhash(AnyType x) { int hashVal = x.hashCode(); hashVal %= theLists.length; if(hashVal < 0) { hashVal += theLists.length; } return hashVal; } private static int nextPrime(int n) { } private static boolean isPrime(int n) { } }
Instructions
Write a program that uses this StringCounter to process all words in the provided words file (this file is a spell checking dictionary for unix systems), and calls the printStatistics() method to print out the following pieces of information:
1. total number of buckets 2. number of used and unused buckets 3. average size of non-empty buckets 4. maximum bucket size
Using a table size of 235886, run this program 3 times, with the 3 different hash functions as listed here. For each, collect the output of printStatistics():
1. Sum of ascii values of each String character 2. The horner’s rule-based hash function for English words (the one with the 37 in it). 3. A hash function of your own design.
Describe your results. Which is best? How did your hash function work? I have had quite a bit of trouble with this assignment for the past 11 days now. I am very desperate to get this done (but with a toddler and infant around, nothing is ever easy haha). Here is the assignment. For this assignment you will create a class for counting occurrences of Strings. Effectively, this will be a hashmap from String to int. Do not use java.util.HashMap. This requires you to do some analysis. This should appear in a plain text or PDF file - no Word documents or Excel files allowed.
The StringCounter Use the following class as a starting point for yours. Note that you are using the separate chaining collision resolution strategy, with a fixed table size - no rehashing is required. When you construct a new StringCounter you specify the table size and an object to use for hashing the strings. Update: Note the chicanery required to construct an array of generic classes.
public class StringCounter {
public interface HashFunction { int hash(String key); } private class Pair { public String key; public int count; }
private LinkedList<Pair>[] buckets; private HashFunction hasher;
@SuppressWarnings("unchecked") public StringCounter(int tableSize, HashFunction hasher) { buckets = (LinkedList<Pair>[]) new LinkedList<?>[tableSize]; this.hasher = hasher; }
public void increment(String word) {
}
public int getCount(String word) {
}
public void printStatistics() {
} public String mostCommonWord() { } }

Here is a template of the separate chaining resolution strategy that is supposed to be used.
SEPERATE CHAINING RESOLUTION STRATEGY
public class SeparateChainingHashTable<AnyType> { public SeparateChainingHashTable() { This (DEFAULT_TABLE_SIZE); } public SeparateChainingHashTable(int size) { theLists = new LinkedList[nextPrime (size)]; for (int i = 0; i < theLists.length; i++) { theLists[i] = new LinkedLists<>(); } } public void insert(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; if (!whichList.contains (x)) { whichList.add(x); } } public void remove(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; if (whichList.contains (x)) { whichList.remove(x); currentSize--; } } public boolean contains(AnyType x) { List<AnyType> whichList = theLists[myhash (x) ]; return whichList.contains(x); } public void makeEmpty() { for(int i = 0; I < theLists.length; i++) { theLists[i].clear(); } currentSize = 0; } private static final int DEFAULT_TABLE_SIZE = 101; private List<AnyType>[] theLists; private int currentSize;    private int myhash(AnyType x) { int hashVal = x.hashCode(); hashVal %= theLists.length; if(hashVal < 0) { hashVal += theLists.length; } return hashVal; } private static int nextPrime(int n) { } private static boolean isPrime(int n) { } }
Instructions
Write a program that uses this StringCounter to process all words in the provided words file (this file is a spell checking dictionary for unix systems), and calls the printStatistics() method to print out the following pieces of information:
1. total number of buckets 2. number of used and unused buckets 3. average size of non-empty buckets 4. maximum bucket size
Using a table size of 235886, run this program 3 times, with the 3 different hash functions as listed here. For each, collect the output of printStatistics():
1. Sum of ascii values of each String character 2. The horner’s rule-based hash function for English words (the one with the 37 in it). 3. A hash function of your own design.
Describe your results. Which is best? How did your hash function work?

Explanation / Answer

}