Question: 3. Write a C++ Program that would take a set of integers as keys and then create a hash table of size m, where m
3. Write a C++ Program that would take a set of integers as keys and then create a hash table of size m, where m is user input. Your program must have different options for collision resolving.
The following functions you need to use:
Value Return Function h(k) which will take an integer data k as input and would return the hash value using h(k) = h mod k
Rehash function that takes two inputs: i and k (both integers) and returns the rehash value using the function: rehash(k, i) = (h(k) + i * g) mod m
However, to obtain g you have to call g function that would return 1, c1 + c2i or 10 (k mod 10) depending on option = 1(linear probing), = 2 (quadratic probing), = 3 (double hashing).
Main would declare an array hashtable dynamically to store m number of data where m is hashtable size which is an user input.
[Declare using a pointer, as below
int * hashtable;
int m;
cout << Enter m: ;
cin >> m;
hashtable = new int [m];
]
Then ask for user input about total no of data (N) and using loop, ask for the key, and check if there is collision, if so, call the rehash function by changing i (probe no) until there is no collision. Then fill up the appropriate place with the key.
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
