Answered step by step
Verified Expert Solution
Link Copied!

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 =0;
private static int cost =0;
private int maxSize;
private Integer[] hashTable;
public QuadraticProbing(int maxSize){
this.maxSize = maxSize;
this.hashTable = new Integer[this.maxSize];
}
public int getCost(){
return this.cost;
}
//method to implement getHashIndex
public void getHashIndex(int key){
// Implement getHashIndex here
}
//method to implement quadratic probing
public void probe(int index, int key){
// Implement quadratic probing here
}
}
and complete the code for below mentioned code as well:-
public class LinearProbing {
private static int currentSize =0;
private static int cost =0;
private int maxSize;
private Integer[] hashTable;
public LinearProbing(int maxSize){
this.maxSize = maxSize;
this.hashTable = new Integer[this.maxSize];
}
public int getCost(){
return this.cost;
}
//method to implement getHashIndex
public void getHashIndex(int key){
// Implement getHashIndex here
return key % maxSize;
}
//method to implement linear probing
public void probe(int 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 main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.print("Enter load factor (lambda) between 0.1 and 0.9: ");
double lambda = scan.nextDouble();
double size = Double.valueOf(10000)/lambda;
int hashTableSize = findTheNextPrime((int)size);
System.out.print("Enter probe type (1 for linear, 2 for quadratic): ");
int probeType = scan.nextInt();
int[] randomIntegers = generateRandomIntegers(probeType, 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 =1;
int high = hashTableSize;
if(probeType ==1){
LinearProbing lProbing = new LinearProbing(hashTableSize);
for(int j =0; j10000; j++){
//inputting random value to an array
lProbing.getHashIndex(r.nextInt(high-low)+ low);
}
System.out.println("Actual (average) cost: "+lProbing.getCost()/Double.valueOf(10000));
// call linearExpectedNoOfProbes(lambda);
}
else if(probeType ==2){
// repeat the exact above steps for the quadratic probing
}
//
return theArray;
}
public static void linearExpectedNoOfProbes(double lambda){
double epCost =0.5*(1.0+(1.0/(1.0-lambda)));
System.out.println("Expected cost (from the equation): "+String.format("%,.4f", epCost));
}
public static void quadraticExpectedNoOfProbes(double lambda){
//double epCost = repeat the above step for the quadratic probing;
//*********The error will go away once you implement epCost*********
System.out.println("Expected cost (from the equation): "+String.format("%,.4f", epCost));
}
}-
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

More Books

Students also viewed these Databases questions

Question

=+3. What are the organization's task goals on this issue?

Answered: 1 week ago

Question

How does selection differ from recruitment ?

Answered: 1 week ago