Thanks!
Program -
#include<iostream>
#include <list>
using namespace std;
class Hashing
{
//Size of hash hashTable
int sizeOfHasTable;
///declare a list which point to array
list<int> *hashTable;
public:
//constructor to initialize the size of hash table
Hashing(int V);
//insert all the arr element to hash table
void insertElement(int x);
//this is function which will be used in mapping hash key with
the values
int hashFunction(int x) {
return (x % sizeOfHasTable);
}
void displayHashElement();
};
//declare the hash table size
Hashing::Hashing(int b)
{
this->sizeOfHasTable = b;
hashTable = new list<int>[sizeOfHasTable];
}
//insert element to hash table
void Hashing::insertElement(int key)
{
int index = hashFunction(key);
hashTable[index].push_back(key);
}
//display hash table
void Hashing::displayHashElement() {
for (int i = 0; i < sizeOfHasTable; i++) {
cout << i;
for (auto x : hashTable[i])
cout << " --> " << x;
cout << endl;
}
}
//here the program starts
int main()
{
//array of integers
int arr[] = { 121, 81, 16, 100, 25, 0, 1, 9, 4, 36, 64, 49};
int lengthOfArr = sizeof(arr)/sizeof(arr[0]);
//declare the size of hash hashTable for now it is given as7 ,
if you want you can change it to any number
Hashing hash(17);//hash hashTable size of 7
//insertElement item into hash hashTable
for (int i = 0; i < lengthOfArr; i++)
hash.insertElement(arr[i]);
// display the Hash hashTable
hash.displayHashElement();
return 0;
}
Screenshots-
In C++: Write a hash.cpp that does the following: Write your own main and insert function...
1) Using Java. Insert the key sequence [29, 33, 1, 37, 32, 26, 48, 11 , 40, 17, 36, 12, 41, 25, 30, 23, 28, 39, 6, 43] with hashing by chaining in a hash table with size 17. Use the hash function: h(k) = k mod 17. a) Show the final table. b) Indicate at which insertion the first collision occurred. c) Indicate which index that has the longest chain.
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...
IN JAVA LANGUAGE: For this lab you are required for implement the following methods: 1. public QuadraticProbingHashTable( int size ): As the signature of this method suggests, this is a constructor for this class. This constructor will initialize status of an object from this class based on the input parameter (i.e., size). So, this function will create the array HashTable with the specified size and initialize all of its elements to be null. 2. public int hash(int value, int tableSize...
Please write in java Write a main program that runs the following two recursive methods demonstrating that they work. #1) Write a recursive method writeSquares that accepts an integer n and prints the first n squares with the odd squares in decending order, followed by the even squares in acending order. For example • writeSquares(8): prints . 49 25 9 1 4 16 36 64 • writeSquares(11); prints 121 81 49 25 9 1 2 16 36 64 100 •...
in C++ Code should work for all cases In this assignment you are requested to implement insert, search, and delete operations for an open-addressing hash table with double hashing. Create an empty hash table of size m= 13. Each integer of the input will be a key that you should insert into the hash table. Use the double hashing function h{k, i) = (hı(k) + ih2(k)) mod 13 where hi(k)= k mod 13 and h2(k) = 1+(k mod 11). The...
1.Given a positive integer number says n, write a java program to print the first n squared numbers recursively. Sample run 1: Enter the value of n: 5 ------------------------------------- First 5 square numbers are: 1 4 9 16 25 Sample run 2: Enter the value of n: 10 ------------------------------------- First 10 square numbers are: 1 4 9 16 25 36 49 64 81 100 Sample run 3: Enter the value of n: 12 ------------------------------------- First 12 square numbers are: 1...
c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study the syntax of passing an array as a function parameter) The program prompts the user to first enter the number of tests given in a course, and then prompts him/her to enter the mark for each test. The marks are stored in an array. This takes place in the main() function. It then passes the array to a function named 'average' that calculates and...
Part B (BI). Implement a Red-Black tree with only operation Insert(). Your program should read from a file that contain positive integers and should insert those numbers into the RB tree in that order. Note that the input file will only contain distinct integers. Print your tree by level using positive values for Black color and negative values for Red color Do not print out null nodes. Format for a node: <Node_value>, <Parent_value>). For example, the following tree is represented...
In this project, you will work on the algorithm (discussed in Module 1) to determine the length of the longest sub sequence of consecutive integers in an array You will implement the algorithm using Hash tables. You are provided with sample code (in C++ and Java) representing the linked list-based implementation of Hash tables (as an array of Linked Lists). You could go through the code to understand the implementation of a Hash table and the functions that can be...
Write a Python program that tests the function main and the functions discussed in parts a through g. Create the following lists: inStock - 2D list (row size:10, column size:4) alpha - 1D list with 20 elements. beta - 1D list with 20 elements. gamma = [11, 13, 15, 17] delta = [3, 5, 2, 6, 10, 9, 7, 11, 1, 8] a. Write the definition of the function setZero that initializes any one-dimensional list to 0 (alpha and beta)....