Question: C++ : Implement two hash table classes, Hash_table1 and Hash_table2, which use open addressing for collision resolution. The two hash table classes are very similar.
C++ : Implement two hash table classes, Hash_table1 and Hash_table2, which use open addressing for collision resolution. The two hash table classes are very similar. The requirements for the two hash table classes are given as follows:
1. Both hash table classes take strings as their keys/elements. The maximum width of the strings/keys is 6.
2. Both hash tables use the same hash function which first calculates the product p of all the characters of the key and then returns the index where index=p%hash_size. The pseudo code of the hash function is given as follows.
int hash(const string &key) {
int value = 1;
for (int position = 0; position < max_key_length; position++)
value *= key[position];
value %= hash_size;
if (value < 0) value += hash_size;
return value;
}
3. In both hash table classes, you need to implement:
a. The hash function.
b. A constructor that takes an integer parameter specifying the hash table size (hash_size).
c. The retrieve() method that takes a string key as the input and returns the location (index) of the key in the hash table. If the hash table does not have the key, retrieve() returns -1.
d. The insert() method that takes a string key as the input and inserts it into the hash table. If the key already exists in the table or if the table is full, the insertion will not be completed and -1 is returned. If the key is inserted, the location (index) of the key in the hash table is returned.
e. Class Hash_table1 uses linear probing for collision resolution.
f. Class Hash_table2 uses quadratic probing for collision resolution.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
