Question: 1 . Implement Hash _ table 1 and Hash _ table 2 in files Hash _ table 1 . h / cpp and Hash _
Implement Hashtable and Hashtable in files Hashtablehcpp and Hashtablehcpp respectively.
Implement two hash table classes, Hashtable and Hashtable 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:
Both hash table classes take strings as their keyselements The maximum width of the stringskeys is
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 indexphashsize. The pseudo code of the hash function is given as the follows.
int hashconst string &key
long long tprod ;
for int position ; position maxkeylength; position
tprod keyposition;
int value tprod hashsize;
return value;
Note: keyposition in the hash function refers to digits in the key as characters, not numbers. For example, is a char, not Its value is the ASCII code of which is
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 hashsize
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
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 is returned. If the key is inserted, the location index of the key in the hash table is returned.
e Class Hashtable should use linear probing for collision resolution.
f Class Hashtable should use quadratic probing for collision resolution. clockt start, finish;string input ;Orderedlist ifinput getlinecin input;insertionfile.openinputcstr; olclear; whilegetlineinsertionfile, input olinsertcnt input; htinsertinput; htinsertinput; cout input endl; ifcnt cout "Invalid file name." endl;
else ifinput cout "Enter a string for search:" endl;int searchkeyintval stoiinput;if searchkeyintval use REPEATFACTOR finish clock;if code successelsecout endl "Time: elapsedtime seconds; REPEATFACTOR used" endl endl;else do not use REPEATFACTOR code sequentialsearch
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
