Question: insert(elem): Inserts element elem in the hash table. Your program should return true or false, depending on whether it was inserted or not. Return true
insert(elem): Inserts element elem in the hash table. Your program should return true or false, depending on whether it was inserted or not. Return true if item is inserted, false if it already exists. Throw a NullPointerException if a null value is passed.
contains(elem): Uses the hash table to determine if elem is in the hash table. Your program should return true or false, depending on whether the item exists. Throw a NullPointerException if a null value is passed.
delete(elem): Use the hash table to determine where elem is, delete it from the hash table. Your program should return true if the item is deleted, false if it cant be deleted (an item cant be deleted if it does not exist in the hash table). Throw a NullPointerException if a null value is passed.
printTable(): Print out the hash table.
getSize(): returns the number of elements currently stored in the hashtable
Note that in the contains/delete method, you shouldnt need to search through the entire table to find an element.
Use separate chaining to resolve collisions, keep track of load factor, when its greater than 2/3, double the size and rehash the values. Do not use String.hashCode(), must implement your own algorithm.
public interface InterHashTable {
boolean insert(String value); boolean delete(String value); boolean contains(String value); /* Example output for this function: * * 0: * 1: * 2: cheese, food * 3: table * 4: * / void printTable(); int getSize(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
