Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a data set with 100 integer values. Create a program that uses the divisi

ID: 3824079 • Letter: C

Question

Create a data set with 100 integer values. Create a program that uses the division method of hashing to store the data values into hash tables with table sizes of 7, 51, and 151. Use the linear probing method of collision resolution. Print out the tables after the data values have been stored. Search for 10 different values in each of the three hash tables, counting the number of comparisons necessary. Print out the number of comparisons necessary in each case in tabular form. Share a listing of your program and output. Review other program from your classmates and discuss differences.

Explanation / Answer

code:in java

package linearprobehashing;

import java.util.Random;


public class LinearProbeHashing {

public static void main(String[] args) {
//to store 100 integer values.
int dataSet[]=new int[100];
Random randomGenerator = new Random();
int i;
for (i = 0; i < 100; i++)
{
int randomInt = randomGenerator.nextInt(100);
dataSet[i]=randomInt;
}
int tableSize[]={7,51,151};
HashTable H1 = new HashTable(tableSize[0]);
HashTable H2 = new HashTable(tableSize[1]);
HashTable H3 = new HashTable(tableSize[2]);
for(i=0;i<100;i++)
{
H1.insert(dataSet[i]);
H2.insert(dataSet[i]);
H3.insert(dataSet[i]);
}
System.out.println(" Hash Table1: ");
H1.printHashTable();
System.out.println(" Hash Table2: ");
H2.printHashTable();
System.out.println(" Hash Table3: ");
H3.printHashTable();
int searchSet[]=new int[10];
for (i = 0; i < 10; i++)
{
int randomInt = randomGenerator.nextInt(100);
searchSet[i]=randomInt;
}
int count[]=new int[3];
for (i = 0; i < 3; i++)
{
count[i]=0;
}
for (i = 0; i < 10; i++)
{
count[0]+=H1.search(searchSet[i]);
}
System.out.println(tableSize[0]+" "+count[0]);
for (i = 0; i < 10; i++)
{
count[1]+=H2.search(searchSet[i]);
}
System.out.println(tableSize[1]+" "+count[1]);   
for (i = 0; i < 10; i++)
{
count[2]+=H3.search(searchSet[i]);
}
System.out.println(tableSize[2]+" "+count[2]);
System.out.println("Table sizes Vs Comparisions");
for (i = 0; i < 3; i++)
{
System.out.println(tableSize[i]+" "+count[i]);
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote