Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete given codes: - public class QuadraticProbing { private static int currentSize = 0 ; private static int cost = 0 ; private int maxSize;
Complete given codes:
public class QuadraticProbing
private static int currentSize ;
private static int cost ;
private int maxSize;
private Integer hashTable;
public QuadraticProbingint maxSize
this.maxSize maxSize;
this.hashTable new IntegerthismaxSize;
public int getCost
return this.cost;
method to implement getHashIndex
public void getHashIndexint key
Implement getHashIndex here
method to implement quadratic probing
public void probeint index, int key
Implement quadratic probing here
and complete the code for below mentioned code as well:
public class LinearProbing
private static int currentSize ;
private static int cost ;
private int maxSize;
private Integer hashTable;
public LinearProbingint maxSize
this.maxSize maxSize;
this.hashTable new IntegerthismaxSize;
public int getCost
return this.cost;
method to implement getHashIndex
public void getHashIndexint key
Implement getHashIndex here
return key maxSize;
method to implement linear probing
public void probeint index, int key
Implement linear probing here
also complete code for this code as well and use that as the main method:
You must use all the given methods without changing their signature.
However you may add new methods using the given ones if necessary.
import java.util.Random;
import java.util.Scanner;
public class HashingTester
public static void mainString args
Scanner scan new ScannerSystemin;
System.out.printEnter load factor lambda between and : ;
double lambda scan.nextDouble;
double size Double.valueOflambda;
int hashTableSize findTheNextPrimeintsize;
System.out.printEnter probe type for linear, for quadratic: ;
int probeType scan.nextInt;
int randomIntegers generateRandomIntegersprobeType hashTableSize, lambda;
method to find the next prime integer
public static int findTheNextPrime int N
Implement checkMove here
The error will go away once you implement and returns an int value
method to find the next prime integer
public static int generateRandomIntegers int probeType, int hashTableSize, double lambda
int theArray new int hashTableSize;
Random r new Random;
int low ;
int high hashTableSize;
ifprobeType
LinearProbing lProbing new LinearProbinghashTableSize;
forint j ; j; j
inputting random value to an array
lProbing.getHashIndexrnextInthighlow low;
System.out.printlnActual average cost: lProbing.getCostDoublevalueOf;
call linearExpectedNoOfProbeslambda;
else ifprobeType
repeat the exact above steps for the quadratic probing
return theArray;
public static void linearExpectedNoOfProbesdouble lambda
double epCost lambda;
System.out.printlnExpected cost from the equation: String.formatf epCost;
public static void quadraticExpectedNoOfProbesdouble lambda
double epCost repeat the above step for the quadratic probing;
The error will go away once you implement epCost
System.out.printlnExpected cost from the equation: String.formatf epCost;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started