Create a hash table class/struct.in C++
Define an array that holds 27 elements.
Define a function called Hash(int)
-This function returns the modulo of that int by the size of the table (array).
Define an add function that takes an integer.
-This function takes the integer, determines the hash of that number by calling the above hash function, then adds it to the table using linear probing for collision resolution.
Define a function that looks up a value, it takes an integer, return -1 if the value is not in the table.
Create a main that allows the user to add and lookup items in the table.
ANSWER:
GIVEN THAT:
Create a hash table class/struct.in
PROGRAM:-
#include <iostream>
#include <stdlib.h>
#define tableSize 27
using namespace std;
int hashTable[tableSize];
int Hash(int n)
{
return n%tableSize;
}
void add(int n)
{
int index = Hash(n);
int count = 0;
while(count < tableSize)
{
if (hashTable[index] == -1)
{
hashTable[index] = n;
break;
}
else
{
index = (index + 1) % tableSize;
count++;
}
}
}
void printArray()
{
for(int i = 0; i < tableSize; i++)
{
cout << hashTable[i] << " ";
}
cout << endl;
}
int lookup(int n)
{
int index = Hash(n);
int count = 0;
while(count < tableSize)
{
if (hashTable[index] == n)
{
return n;
}
else
{
index = (index + 1) % tableSize;
count++;
}
}
return -1;
}
int main()
{
for(int i = 0; i < tableSize; i++)
{
hashTable[i] = -1;
}
while(true)
{
cout << "Choose from given menu: " << endl;
cout << "1. Add element to hash." << endl;
cout << "2. Lookup value in hash" << endl;
cout << "Any other key to quit" << endl;
int choice;
cin >> choice;
if(choice == 1)
{
cout << "Enter number to be added: ";
int n;
cin >> n;
add(n);
}
else if (choice == 2)
{
cout << "Enter number to be searched: ";
int n;
cin >> n;
if(lookup(n) != -1)
{
cout << " Found" << endl;
}
else
{
cout << " Not found." << endl;
}
}
else
{
break;
}
}
return 0;
}
The above program output:-

Create a hash table class/struct.in C++ Define an array that holds 27 elements. Define a function...
This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...
Name: Hash Tables CS 2020 Hw 14 edefine MAX CAPACITY 11 #define R struct HashTable f int hashtable[MAX CAPACITY]: 1/ table to store values int countj // count of values currently stored int hash1(int value) ( return (value % MAX CAPACITY); int hash2(int value) ( return (R- (value % R)); 1) Use hash1 function and linear probing as a collision resolution strategy, insert the following elements into the correct index of the hash table: 1, 5, 4, 11, 21, 15,...
Java using data structures The objective is to create your own Hash Table class to hold a list of employees and their ID numbers. I've provided the TableEntry class which will be each data object in the hash table. The list of employees will be provided as a .txt file and must be read with the code. please create a .txt file called Employees.txt with the info provided so that the java code can read it in. Employees.txt: (No WhiteSpace...
Insert elements into a hash table implemented using chain hashing, as an array of linked list in which each entry slot is as a linked list of key/value pairings that have the same hash (outcome value computed using certain hash function). You are allowed to use “Hash Function”, h(k) = k % x where, x is the value you will need to decide to use, that you find appropriate for this implementation. The main requirements are the following: 1. Input:...
C++: Create a class called "HashTable" This class will implement hashing on an array of integers Make the table size 11 Implement with linear probing. The hash function should be: h(x) = x % 11 Create search(), insert() and delete() member functions. Search should return the index of where the target is located, insert should allow the user to insert a value, and delete removes the desired value from the table. In main perform the following: 1. Insert: 17 11...
Write a c++ program that does the following
Create an integer array of size 30. Assign -1 to each location in the array indicating that the array is empty. Populate half of the array with random integer values between 100 and 500 inclusive. Use the following formula in order to hash and store each number in its proper position/location. Generated Number Table Size: Should a collision occurs, use linear probing to find next available position location. Use the following probing...
IN JAVA USING ECLIPSE The objective of this assignment is to create your own hash table class to hold employees and their ID numbers. You'll create an employee class to hold each person's key (id number) and value (name). Flow of the main program: Create an instance of your hash table class in your main method. Read in the Employees.txt file and store the names and ID numbers into Employee objects and store those in your hash table using the...
Question 8: (a) We create a Hash Table of size 7, using open addressing and linear probing with the hash function h(n)=n%7. Write the content of the array after inserting the following values in sequence: 11, 28,46, 7,67, 88,0. (3 marks) . loj [1] [2] [3] [41-5] 问 (b) Explain the issue linear probing has and how it can be addressed. (3 marks)
C programming Problem 3 [Set via Hashing] As mentioned in the lecture, a hash table can be used to implement a Set ADT. Let's try to use the template below to implement a Set with double hashing. Here we assume the Set contains names with 3 characters long. Since it is a Set, we do not need to have an explicit value for each key. We will use a token value of 1 if a name belongs to the Set....
IN C++ Create a student hash table that contains information, studentID (int), name (string), marks_oop345 (float). The size of hash table is equal to the number of students in the class. Use linear probing in case of collisions. Perform insertion, deletion, display and search operations.