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

Create initializer/constructor functions for book. Declare and implement functions like insert book(insert at End, InsertAtFirst), retrieve...
Create initializer/constructor functions for book. Declare and implement functions like insert book(insert at End, InsertAtFirst), retrieve book, update book information book using ISBN number in Library. Declare another function named Search to find a specific book from catalogue. #include<iostream.h> #include<conio.h> struct book{ char name[50]; int ISBN; char authorname[50]; char publishername[50]; int issuedate; int issuemonth; int issueyear; int retdate; int retmonth; int retyear; struct book *next=NULL; } void insert(struct book *head){ if *head.next==NULL{ struct book node; cout<<"enter the name of book";...
(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...
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...
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);...
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...
Suppose that we are using extendable hashing on a file that contains records with the following...
Suppose that we are using extendable hashing on a file that contains records with the following search-key values: (2, 3, 5, 7, 11, 17, 19, 23, 29, 31). Show the final extendable hash structure for this file if the hash function is h(x) = x mod 8 and buckets can hold three records. Recall that: 1. the bucket address table is indexed by the prefix of the binary representation of h(x). 2. Initially i = 0, i.e. the prefix consists...
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...
Write a program to implement linked list data structure that will have following functions: a. Append...
Write a program to implement linked list data structure that will have following functions: a. Append a node in the list b. Insert a node in the list c. Delete a node from the list d. Display list e. Find maximum value in the list f. Find how many times a value exists in the list. g. Search Portion of the code is give below. You have to write code for the items (e, f, g) Program: #include<stdlib.h> #include<stdio.h> #include<iostream>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT