ALGORITHMS AND DATA STRUCTURES 2 TOPIC 5: HASHING FORMATIVE EXERCISE In this activity, you will work individually to imp
Posted: Sat May 14, 2022 4:20 pm
Please provide code written
in C++ and it is
important that it follows the requirements listed and most
importantly that it uses the methods and functions exactly as given
above. If you are going to respond please explain the
answer and not just paste it to get a thumbs up. All question has
been uploaded and it is clear of the
requirements. It must follow the provided methods
and functions, please. Respond with a good and
verified answer as wrong answers would be given a
thumbs down. Thank you for your help. Do not
post wrong answers please.
ALGORITHMS AND DATA STRUCTURES 2 TOPIC 5: HASHING FORMATIVE EXERCISE In this activity, you will work individually to implement a hash table with linear probing. PART 1: YOUR TASK In this formative exercise, your task is to implement a hash table with linear probing. The hash function to implement is as follows: h(k)=(a*k+c) mod m where coefficients a, c and m are positive integer numbers and m is the number of buckets of the hash table. The client of the hash table will specify these parameters. This exercise will be automatically graded. Thus, you are provided with two files: HashTable.cpp and HashTable.hpp. Your task is to complete the code that makes the methods in that skeleton code operative. You must not change the prototypes of the methods. You can add other methods and variables if you want.
PART 2: THE METHODS Please, look at the content of the skeleton files you are provided with for this formative exercise (HashTable.cpp and HashTable.hpp). You can see there are seven methods you must implement in the.cpp file: HashTable: This is a constructor that initialises the values of a, c and m (a takes the value of_a, c the value of_c and m the value of_m) and allocates memory space (to store m integer values) to the hash table buckets. . -HashTable: This method deletes the hash table. • insert: This function is in charge of inserting strictly positive numbers into the hash table, using linear probing for collision resolution. The number to insert is stored in the variable key (the input argument of the function). If the load factor of the hash table is already 1 when a new number is going to be inserted, you have to apply extend and rehash. You choose the value of the extension factor of the hash table. • extend: This method increases the size of the hash table. To do so, you must create a new (bigger) array temporarily storing the content of the hash table. Then, you increase the size of buckets (using new) and rehash the contents of the temporary array into buckets. • find: This function searches for the number key (the input argument of the function) in the hash table. If the number is found, it returns true. Otherwise, it must return false. remove: This function removes the number key (the input argument of the function) from the hash table. Remember that, because of linear probing, a number present in the hash table might not be in its natural position. • loadFactor: This function returns, as a double, the fraction of total hash buckets that are occupied.
e HashTable.hpp X GHashTable.hpp 1 #ifndef HASHTABLE_HPP 2 #define HASHTABLE_HPP 3 4 class HashTable { 5 public: // for testing purposes 6 int *buckets = 0; 7 public: 8 HashTable(long, long, long); 9 9 -HashTable(); 10 void insert(int); 11 void extend(); 12 bool find(int); 13 void remove(int); 14 double loadFactor(); 15 16 17 #endif 18 0 0 };
GHashTable.cpp X GHashTable.cpp 1 1 #include "HashTable.hpp" 2 3 HashTable::HashTable(long da, long _c, long _m) { 4 } 5 6 HashTable::-HashTable() { 7 } 8 9 void HashTable::insert(int key) { 10 } 11 12 void HashTable::extend() { 13 } 14 15 bool HashTable::find(int key) { 16 return false; 17 } 18 19 void HashTable::remove(int key){ 20 } 21 22 double HashTable::loadFactor() { 23 return 0.0; ; 24 } 25 26
in C++ and it is
important that it follows the requirements listed and most
importantly that it uses the methods and functions exactly as given
above. If you are going to respond please explain the
answer and not just paste it to get a thumbs up. All question has
been uploaded and it is clear of the
requirements. It must follow the provided methods
and functions, please. Respond with a good and
verified answer as wrong answers would be given a
thumbs down. Thank you for your help. Do not
post wrong answers please.
ALGORITHMS AND DATA STRUCTURES 2 TOPIC 5: HASHING FORMATIVE EXERCISE In this activity, you will work individually to implement a hash table with linear probing. PART 1: YOUR TASK In this formative exercise, your task is to implement a hash table with linear probing. The hash function to implement is as follows: h(k)=(a*k+c) mod m where coefficients a, c and m are positive integer numbers and m is the number of buckets of the hash table. The client of the hash table will specify these parameters. This exercise will be automatically graded. Thus, you are provided with two files: HashTable.cpp and HashTable.hpp. Your task is to complete the code that makes the methods in that skeleton code operative. You must not change the prototypes of the methods. You can add other methods and variables if you want.
PART 2: THE METHODS Please, look at the content of the skeleton files you are provided with for this formative exercise (HashTable.cpp and HashTable.hpp). You can see there are seven methods you must implement in the.cpp file: HashTable: This is a constructor that initialises the values of a, c and m (a takes the value of_a, c the value of_c and m the value of_m) and allocates memory space (to store m integer values) to the hash table buckets. . -HashTable: This method deletes the hash table. • insert: This function is in charge of inserting strictly positive numbers into the hash table, using linear probing for collision resolution. The number to insert is stored in the variable key (the input argument of the function). If the load factor of the hash table is already 1 when a new number is going to be inserted, you have to apply extend and rehash. You choose the value of the extension factor of the hash table. • extend: This method increases the size of the hash table. To do so, you must create a new (bigger) array temporarily storing the content of the hash table. Then, you increase the size of buckets (using new) and rehash the contents of the temporary array into buckets. • find: This function searches for the number key (the input argument of the function) in the hash table. If the number is found, it returns true. Otherwise, it must return false. remove: This function removes the number key (the input argument of the function) from the hash table. Remember that, because of linear probing, a number present in the hash table might not be in its natural position. • loadFactor: This function returns, as a double, the fraction of total hash buckets that are occupied.
e HashTable.hpp X GHashTable.hpp 1 #ifndef HASHTABLE_HPP 2 #define HASHTABLE_HPP 3 4 class HashTable { 5 public: // for testing purposes 6 int *buckets = 0; 7 public: 8 HashTable(long, long, long); 9 9 -HashTable(); 10 void insert(int); 11 void extend(); 12 bool find(int); 13 void remove(int); 14 double loadFactor(); 15 16 17 #endif 18 0 0 };
GHashTable.cpp X GHashTable.cpp 1 1 #include "HashTable.hpp" 2 3 HashTable::HashTable(long da, long _c, long _m) { 4 } 5 6 HashTable::-HashTable() { 7 } 8 9 void HashTable::insert(int key) { 10 } 11 12 void HashTable::extend() { 13 } 14 15 bool HashTable::find(int key) { 16 return false; 17 } 18 19 void HashTable::remove(int key){ 20 } 21 22 double HashTable::loadFactor() { 23 return 0.0; ; 24 } 25 26