Using Java, build a hash table class with the following characteristics: • • Your hash table must be dynamically allocated. The constructor for your hash table should be able to accept an integer (n) as a parameter and creates a hash table such that the size of the table is equal to the next prime number which is greater than (n). • • A hash function is used to produce a Semi-unique address for a given key to be stored in the hash table. The following functions need to be included: O Division Method o Folding Method o Truncation Method o Mid-Square Method o Radix Conversion • Despite our best effort in selecting a good hash function, often multiple keys hash into the same hash table location. In such cases, we must be able to deal with the collision. Use a binary tree object as the overflow area to handle collisions. Write an Experiment () function. This function should take several parameters including, table size, number of records or keys to be inserted, lower and upper range of key values, hash function to be used, overflow (this this assignment, the only value will be “BINARY_TREE”, but in the future, the program can be extended to accept other parameters such as “LINKED_LIST” or “OPEN_ADDRESSING”). When the function is called, it should instantiate a HashTable with appropriate dimensions, then call a function to generate appropriate number of random keys and insert them into the hash table. The keys of course should come from the appropriate domain (lower and upper range). It should produce a report showing the following information: o Experiment Parameters: Table Size: XX o Number of Keys Inserted: XXX o Lower Range: XXXX o Upper Range: XXXX • Your hash class may look like the following: class Hash { HashNode[HashTable; int Size; String HashFunction; // Hash Functions: public static final String DIVISION = “DIVISION”; public static final String FOLDING – “FOLDING”; public static final String TRUNCATION – “TRUNCATION”; public static final String MIDSQUARE = “MIDSQUARE”; public static final String RADIXCONVERSION = “RADIXCONVERSIOIN”; // ———————————— Hash (int size, String hash_function); public boolean is Prime (int number); public int next Prime (int starting point); public void Print(); public void Insert (int key); public int Division Method (int key); public int FoldingMethod (int key); public int TruncationMethod (int key); public int MidSquareMethod (int key); public int RadixConversionMethod (int key); public int Experiment (int Table Size, int Num Keys, int Lower key Range, int Upper_Key_Range, String HashFunction, String OverflowMechanism); Show transcribed image text Using Java, build a hash table class with the following characteristics: • • Your hash table must be dynamically allocated. The constructor for your hash table should be able to accept an integer (n) as a parameter and creates a hash table such that the size of the table is equal to the next prime number which is greater than (n). • • A hash function is used to produce a Semi-unique address for a given key to be stored in the hash table. The following functions need to be included: O Division Method o Folding Method o Truncation Method o Mid-Square Method o Radix Conversion • Despite our best effort in selecting a good hash function, often multiple keys hash into the same hash table location. In such cases, we must be able to deal with the collision. Use a binary tree object as the overflow area to handle collisions. Write an Experiment () function. This function should take several parameters including, table size, number of records or keys to be inserted, lower and upper range of key values, hash function to be used, overflow (this this assignment, the only value will be “BINARY_TREE”, but in the future, the program can be extended to accept other parameters such as “LINKED_LIST” or “OPEN_ADDRESSING”). When the function is called, it should instantiate a HashTable with appropriate dimensions, then call a function to generate appropriate number of random keys and insert them into the hash table. The keys of course should come from the appropriate domain (lower and upper range). It should produce a report showing the following information: o Experiment Parameters: Table Size: XX o Number of Keys Inserted: XXX o Lower Range: XXXX o Upper Range: XXXX •
Your hash class may look like the following: class Hash { HashNode[HashTable; int Size; String HashFunction; // Hash Functions: public static final String DIVISION = “DIVISION”; public static final String FOLDING – “FOLDING”; public static final String TRUNCATION – “TRUNCATION”; public static final String MIDSQUARE = “MIDSQUARE”; public static final String RADIXCONVERSION = “RADIXCONVERSIOIN”; // ———————————— Hash (int size, String hash_function); public boolean is Prime (int number); public int next Prime (int starting point); public void Print(); public void Insert (int key); public int Division Method (int key); public int FoldingMethod (int key); public int TruncationMethod (int key); public int MidSquareMethod (int key); public int RadixConversionMethod (int key); public int Experiment (int Table Size, int Num Keys, int Lower key Range, int Upper_Key_Range, String HashFunction, String OverflowMechanism);
Expert Answer
Answer to Using Java, build a hash table class with the following characteristics: • • Your hash table must be dynamically all…