Question: 1 . Implement Hash _ table 1 and Hash _ table 2 in files Hash _ table 1 . h / cpp and Hash _

1. Implement Hash_table1 and Hash_table2 in files Hash_table1.h/cpp and Hash_table2.h/cpp respectively.
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 the follows.
int hash(const string &key){
long long t_prod =1;
for (int position =0; position max_key_length; position++)
t_prod *= key[position];
int value = t_prod % hash_size;
return value;
}
Note: key[position] in the hash function refers to digits in the key as characters, not numbers. For example, '0' is a char, not 0. Its value is the ASCII code of '0', which is 48.
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, which 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 operation 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 should use linear probing for collision resolution.
f. Class Hash_table2 should use quadratic probing for collision resolution. clock_t start, finish;string input ="";Ordered_list if(input =="1"){getline(cin, input);insertion_file.open(input.c_str()); ol.clear(); while(getline(insertion_file, input)){ ol.insert(cnt, input); ht2.insert(input); ht4.insert(input); //cout input endl; if(cnt%10000==0)} cout "Invalid file name." endl;
}
else if(input =="2"){cout "Enter a string for search:" endl;int search_key_int_val = stoi(input);if (search_key_int_val =1000){// use REPEAT_FACTOR finish = clock();if (code == success)elsecout endl "Time: " elapsed_time " seconds; REPEAT_FACTOR used" endl endl;else {// do not use REPEAT_FACTOR code = sequential_search
1 . Implement Hash _ table 1 and Hash _ table 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!