Question: please answer / * This is a program to explore collision resolution in hashing * NUMITEMS is the number of items to be inserted *
please answer
This is a program to explore collision resolution in hashing
NUMITEMS is the number of items to be inserted
PRIME should be a prime number that is larger than twice NUMITEMS
quadratic collision resolution will not work otherwise
PRIME is used in double hashing and must be less than PRIME
SEED is the seed for the random number generator
it is needed to compare the methods for the same list of pseudo random numbers
change the value to get a different sequence
change "new RandomSEED to "new Random to get a different sequence every time
import java.util.;
public class LabHashing
static final int NUMITEMS ;
static final int PRIME;
static final int PRIME;
static final int SEED ;
static Random rand;
public static void mainString args
System.out.printlnLinear Probing";
rand new RandomSEED;
HashLinear tableLinear new HashLinearPRIME;
hashIttableLinear;
System.out.printlnQuadratic Probing";
rand new RandomSEED;
HashQuadratic tableQuadratic new HashQuadraticPRIME;
hashIttableQuadratic;
System.out.printlnDouble Hash Probing";
rand new RandomSEED;
HashDouble tableDouble new HashDoublePRIMEPRIME;
hashIttableDouble;
static void hashItHash table
int total ;
forint i; i
int capacity;
E table;
int numCollisions;
public Hashint size
capacity size;
table Enew Objectsize;
public int insertE it
numCollisions ;
int h Math.absithashCode capacity;
if tableh null
tableh it;
return numCollisions;
if tablehequalsit return numCollisions; don't allow duplicates
whiletableh null && tablehequalsit
numCollisions;
h incrementit h;
if tableh null
tableh it;
return numCollisions;
int incrementE it int h
return h capacity;
class HashLinear extends Hash
public HashLinearint size
supersize;
class HashQuadratic extends Hash
public HashQuadraticint size
supersize;
int incrementE it int h
return h numCollisions capacity;
class HashDouble extends Hash
int mod;
public HashDoubleint size, int m
supersize;
mod m;
int incrementE it int h
int hash mod MathabsithashCode mod;
return h hash capacity;
Use LabHashing.java as a starting point.
It provides a very simple implementation of hashing that you can use to explore three
collision resolution methods.
Change values of the constants that are defined at the beginning of the program to
examine
What happens when the load factor increases? Above you may have to comment
out the quadratic hashing call.
What effect does PRIME have on double hashing?
What other interesting effects can you find?
create a Word document with graphs of your collision
resolution counts and observation:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
