Please complete the following task: Create a C++ hash table program for generating a hash from a string.
Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function).
Requirements:
Please use only #include, #include, and #include.
Link to the word.txt file contents: (file:///C:/words.html)
I have answered the similar question before. The same program I am attaching with necessary changes. Below is the program which solves your question completely. Since you haven't provided any words.txt I have taken a file which contains of 30 words and solved using that but this works for any size. To change the size, just to the program and on the top you will see a line like "#define SIZE 30". There remove 30 and keep the size whatever you want.
INPUT:
CODE:
############################
#include<iostream>
#include<fstream>
using namespace std;
#define SIZE 30
long hashArray[SIZE];
long getHash(string s)
{
long h=0, temp;
for(int i=0;i<s.size();i++)
{
temp = s[i];
h = (h*10+temp)%SIZE;
}
return h;
}
int main()
{
ifstream in_file("words.txt");
string s;
long collisions=0, h;
while(in_file>>s)
{
h = getHash(s);
hashArray[h]++;
if(hashArray[h]>1) collisions++;
}
cout<<"Total size of hash array: "<<SIZE;
cout<<"\n\nNumber of collisions: "<<collisions;
cout<<"\n\nPercentage of collisions:
"<<(double)(collisions*100)/SIZE<<"\n\n";
//exporting to csv file
ofstream out_file("hashresults.csv");
for(long i=0;i<SIZE;i++)
{
out_file<<i<<','<<hashArray[i]<<'\n';
}
}
##############################
OUTPUT:
Please complete the following task: Create a C++ hash table program for generating a hash from a string. Create a hash f...
I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...
I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...
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...
in java, Hash 8 randomly generated int values (in the range [ 0 - 99 ] inclusive). The random number generator is initially seeded to value 97. Each generated value is stored in a hash table size 11. The first hash function, h1(key) is the division modulo sizeof(table). I.e., h1(key) = key % sizeof(table) h1(key) = key % 11. Any collisions will NOT be stored in the hash table. You will ignore collisions. The hash table is a random access...
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...
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...
Follow the TODOs and complete the insertItem(), searchItem() and printTable() functions in hash.cpp. The hash function has already been implemented for you. // hash.CPP program to implement hashing with chaining #include<iostream> #include "hash.hpp" using namespace std; node* HashTable::createNode(int key, node* next) { node* nw = new node; nw->key = key; nw->next = next; return nw; } HashTable::HashTable(int bsize) { this->tableSize= bsize; table = new node*[tableSize]; for(int i=0;i<bsize;i++) table[i] = nullptr; } //function to calculate hash function unsigned int HashTable::hashFunction(int key)...
Please answer this problem in C++, Thank you! Read and study the sample program: "hashing with chaining using singly linked lists", as well as "hashing with chaining using doubly linked lists". Notice this program is complete except it doesn't include the remove function. Write the remove function and test it with the rest of the program including the given main program. Upload your C++ source file. ---Here is the referenced program: "hashing with chaining using singly linked lists". Below this...
0. Introduction. This involves designing a perfect hash function for a small set of strings. It demonstrates that if the set of possible keys is small, then a perfect hash function need not be hard to design, or hard to understand. 1. Theory. A hash table is an array that associates keys with values. A hash function takes a key as its argument, and returns an index in the array. The object that appears at the index is the key’s...
For this problem, you have to use following hash function: key modulo the number of buckets. Input format: This program takes a file name as argument from the command line. The file is either blank or contains successive lines of input. Each line contains a character, either ‘i’ or ‘s’, followed by a tab and then an integer, the same format as in the Second Part. For each of the lines that starts with ‘i’, your program should insert that...