Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the following Java class without using any external libraries or inbuilt classes such as HashMap, HashTable, etc. This class will implement a hash table.

image text in transcribed

Write the following Java class without using any external libraries or inbuilt classes such as HashMap, HashTable, etc. This class will implement a hash table. The hash table will hold data items whose type is tuple. This class will have following public methods and constructor. HashTable (int size) Finds the smallest prime integer p whose value is at least size. Creates a hash table of size p where each cell initially is NULL. It will determine the hash function to be used in the hash table by creating the object new HashFunction (p). max Load () Returns the maximum load of the hash table average Load () Returns the average load of the hash table size() returns the current size of the hash table. num Elements () returns the number of Tuples that are currently stored in the hash table. load Factor () return the load factor which is num Elements()/size() add Tuple t) Adds the tuple t to the hash table; places t in the list pointed by the cell h (t.getKey()) where h is the hash function that is being used. When the load factors becomes bigger than 0.7, then it (approximately) doubles the size of the hash table and rehashes all the elements (tuples) to the new hash table. The size of the new hash table must be: Smallest prime integer whose value is at least twice the current size. search (int k) returns an array list of Tuples (in the hash table) whose key equals k. If no such Tuples exist, returns an empty list. Note that the type of this method must be ArrayList remove (Tuple t) Remove t from the hash table

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions