Question

In: Computer Science

Implement one of the hashing procedures that we have discussed, and the following related functions: INSERT...

Implement one of the hashing procedures that we have discussed, and the following related functions:

  • INSERT (item)
  • DELETE (item)
  • FIND (item)

Make sure that your program correctly handles collisions and full hash table!

Solutions

Expert Solution

ANSWER :

Given related functions:-

  • INSERT (item)
  • DELETE (item)
  • FIND (item)

(you dont mention any spwcific program ,so i answered in c++)

The program for the implementation of the HashTable is as below

HashTbl.cpp

#include<istream>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;
const int SIZE_OF_TBL = 128;

class HashTbl
{
public:
int keys;
int val;
HashTbl(int keys, int val)
{
this->keys = keys;
this->val = val;
}
};

class HashTblMapping
{
private:
HashTbl **tble;
public:   
HashTblMapping()
{
tble = new HashTbl * [SIZE_OF_TBL];
for (int uu = 0; uu< SIZE_OF_TBL; uu++)
{
tble[uu] = NULL;
}
}

// Hashing functions
int HashF(int keys)
{
return keys % SIZE_OF_TBL;
}

//Inserting values using Hashes
void HashValuesInsert(int keys, int val)
{
int hs = HashF(keys);
while (tble[hs] != NULL && tble[hs]->keys != keys)
{
hs = HashF(hs + 1);
}
if (tble[hs] != NULL)
delete tble[hs];
tble[hs] = new HashTbl(keys, val);
}
//Searching for the elements using keys
int Find(int keys)
{
int hs = HashF(keys);
while (tble[hs] != NULL && tble[hs]->keys != keys)
{
hs = HashF(hs + 1);
}
if (tble[hs] == NULL)
return -1;
else
return tble[hs]->val;
}

// Deleting element using the keys
void Delete(int keys)
{
int hs = HashF(keys);
while (tble[hs] != NULL)
{
if (tble[hs]->keys == keys)
break;
hs = HashF(hs + 1);
}
if (tble[hs] == NULL)
{
cout<<"Elements was not found using the keys: "<<keys<<endl;
return;
}
else
{
delete tble[hs];
}
cout<<"Element is successfully deleted...."<<endl;
}
~HashTblMapping()
{
for (int uu = 0; uu < SIZE_OF_TBL; uu++)
{
if (tble[uu] != NULL)
delete tble[uu];
delete[] tble;
}
}
};

// Driver program
int main()
{
HashTblMapping hs;
int keys, val;
int ch;
while (1)
{
cout<<"\n----------------------"<<endl;
cout<<"Implementation Of HashTable"<<endl;
cout<<"\n----------------------"<<endl;
cout<<"1. Inserting Elements Using Keys"<<endl;
cout<<"2. Finding Elements Using Keys"<<endl;
cout<<"3. Deleting Elements Using Keys"<<endl;
cout<<"4.Exit"<<endl;
cout<<"Please enter a valid selection: ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Please enter the element to be inserted: ";
cin>>val;
cout<<"Please enter keys at which the element is to be inserted: ";
cin>>keys;
hs.HashValuesInsert(keys, val);
break;
case 2:
cout<<"Please enter the keys which you want to search: ";
cin>>keys;
if (hs.Find(keys) == -1)
{
cout<<"No particular element was found...."<<keys<<endl;
continue;
}
else
{
cout<<"Element found using keys: "<<keys<<" : ";
cout<<hs.Find(keys)<<endl;
}
break;
case 3:
cout<<"Please enter the element of the keys to be deleted: ";
cin>>keys;
hs.Delete(keys);
break;
case 4:
exit(1);
default:
cout<<"\nInvalid Option.....Try entering valid option.\n";
}
}
return 0;
}

Output:


Related Solutions

(Python or C++) We are going to implement the following scheduling algorithms that we discussed in...
(Python or C++) We are going to implement the following scheduling algorithms that we discussed in class: 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with different quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the...
In this assignment please relate one of the following economic concepts we have discussed to a...
In this assignment please relate one of the following economic concepts we have discussed to a personal experience you have had since the COVID-19 pandemic began. Chapter 1: marginal analysis Chapter 2: trade off Chapter 3: a shift in supply and demand (book: Hubbard and O'Brien 3rd edition Macroeconomics) Your assignment should explain the concept you chose and how it relates to a personal experience over the past couple weeks. I would recommend your response contain 2-5 paragraphs in to...
We have discussed the fact that managers have some discretion in making accounting-related decisions. Due to...
We have discussed the fact that managers have some discretion in making accounting-related decisions. Due to the COVID-19 situation, companies likely will have lower earnings in 2020 than in 2019. Assume that for 2020, a company wants to do what it can so that its financial statements look as “good” to investors as they did in 2019. Discuss AND give explanations on EACH of the judgmental decisions the company might make with respect to: Accounting for accounts receivable/allowance for doubtful...
USE ONLY THE BELOW FUNCTIONS AND IMPLEMENT THE MISSING PART implement the following missing functions from...
USE ONLY THE BELOW FUNCTIONS AND IMPLEMENT THE MISSING PART implement the following missing functions from the implementation: * reset * intersection * difference Set Set::intersection(Set& s){ Set r; // find intersection return r; } Set Set::difference(Set& s){ Set r; // find difference return r; } void Set::reset(int c){ // increase the capacity and clear the data } driver program int a1[] = {10,5,7,3,9}; Set s1(5); s1.insert(a1,5); s1.print("s1"); int a2[] = {2,9,6}; Set s2(3); s2.insert(a2,3); s2.print("s2"); Set s3 = s1.unionset(s2);...
This semester we have discussed the following statistical analyses.              Z-test               One-Sample t-test
This semester we have discussed the following statistical analyses.              Z-test               One-Sample t-test                   Independent Groups t-test                  Repeated Measures t-test One-Way ANOVA                             Regression                                           Correlation 1. Research shows that people who do well on the SAT tend to do well in college (they have a higher GPA). Likewise, students who do not do well on the SAT struggle in college (they have a lower GPA). This information is used by college admissions officials to determine if a student should...
One of the key concepts we have discussed this semester is the concept of “Elasticity”. Generally...
One of the key concepts we have discussed this semester is the concept of “Elasticity”. Generally speaking, elasticity is simply a measure of how responsive one variable is to a change in another variable. While we have focused on the “own price elasticity of demand”, the “income elasticity of demand” and the “cross-price elasticity of demand” this concept can be extended to a number of different situations. (10 pts) The demand curve for a product is given by Qx=1,000-2Px+0.02Pz,  where Pz...
We discussed acceptance test criteria and procedures in some detail. Such requirements are normally included in...
We discussed acceptance test criteria and procedures in some detail. Such requirements are normally included in the buyer-seller contract. From the seller's perspective, getting the buyer to accept one or more deliverables is critical because: A. It's evidence that the seller is doing its job under the contract. B. Acceptance by the buyer normally triggers the buyer's legal obligation to pay for that deliverabe. C. The buyer can't sue the seller for deliverables that are accepted. D. None of the...
Use double hashing and the following hash functions: hash(key) = (key % table size) and hash2(key)...
Use double hashing and the following hash functions: hash(key) = (key % table size) and hash2(key) = (16 - (key % 10)) + 1 to insert the following numbers into a dictionary's hash table: 1, 12, 14, 3, 5 and 17. The table size is 11. Show the table and where each value is inserted. No coding required for this problem.
a. You have to write the steps that we need to insert a new node as...
a. You have to write the steps that we need to insert a new node as the head of an existing linked list. b.You have to write the code in c++ programming language of the function that we need to insert a new node in the end of an existing node. c.Suppose that the below main function is executed correctly and all the functions that are invoked are imported from functions.h file. Explain. int main(){ Node *head=NULL; insertEnd(&head,"John");//inserts a new...
The following questions are conceptual questions on several topics that we have discussed in the course....
The following questions are conceptual questions on several topics that we have discussed in the course. In answering the questions, be clear and to-the-point. The motivation of your answer determines the grade. Suppose you have to choose between three projects. All involve production technologies that will be repeated at the end of their economic lives. Relevant project information is summarized below. Your supervisor expects a recommendation consistent with shareholder value maximization (his compensation package is linked to the share price...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT