Hash Table Part 1: Coding Implement a hash table example as shown in class. Part 1 through Part 13 $CANVAS_OBJECT_REFERENCE$/discussion_topics/g9b650ab085347f28a00e0b2d23cb7dbb Part 2: Concepts You...

1 answer below »
Can u please complete this assignment


Hash Table Part 1: Coding Implement a hash table example as shown in class. Part 1 through Part 13 $CANVAS_OBJECT_REFERENCE$/discussion_topics/g9b650ab085347f28a00e0b2d23cb7dbb   Part 2: Concepts You will also need to explain the concept of Big O as it relates to efficient data searches and access.  This will require that you do some research, read your textbook and take notes on that topic during lecture. Support your explanations with at least three sources from which you will cite properly. https://www.youtube.com/watch?v=shs0KM3wKv8 https://www.youtube.com/watch?v=nvzVHwrrub0 https://www.youtube.com/watch?v=m6n_rozU8dA follow the playlist part 1 thru 13
Answered Same DayApr 11, 2021

Answer To: Hash Table Part 1: Coding Implement a hash table example as shown in class. Part 1 through Part 13...

Kshitij answered on Apr 12 2021
151 Votes
# include
# include
# include
# include
using namespace std
;
class HashTable {
private:
    static const int hashGroups = 10;
    list> table[hashGroups];
public:
    bool isEmpty();
    int hashFunction(int key);
    void insert(int key, string value);
    void remove(int key);
    void print();
    void search(int key);
};
bool HashTable::isEmpty() {
    int sum = 0;
    for (int i{}; i < hashGroups; i++) {
        sum += table[i].size();
    }
    if (!sum) {
        return true;
    }
    return false;
}
int HashTable::hashFunction(int key) {
    return key % hashGroups;
}
void HashTable::insert(int key , string value) {
    int hashValue = hashFunction(key);
    auto& cell = table[hashValue];
    auto bitr = begin(cell);
    bool keyExists = false;
    for ( ; bitr != end(cell); bitr++) {
        if (bitr->first == key) {
            keyExists = true;
            bitr->second = value;
            cout << "key exists and value replaced" << endl;
            break;
        }
    }
    if (!keyExists) {
        cell.emplace_back(key,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here