Question: My code is not giving me the right output, which isExpected output: 0 - > 5 , 1 - > 2 , 2 - >
My code is not giving me the right output, which isExpected output: What do I do to fix this? Here is my code and the interface: import java.util.function.Function;
public class DoubleHashTable implements OpenAddressTable
private int table;
private int size;
private Function h;
private Function h;
public DoubleHashTableint size, Function h Function h
if size
throw new IllegalArgumentExceptionTable size must be greater than ;
this.size size;
this.table new intsize;
this.h h;
this.h h;
@Override
public double loadFactor
int count ;
for int value : table
if value
count;
return double count size;
@Override
public void insertint value
if value
throw new IllegalArgumentExceptionValue must be nonnegative";
int probe ;
int index hashvalue probe;
while tableindex
probe;
index index probe happlyvalue size;
tableindex value;
@Override
public int findint value
int index happlyvalue;
int step happlyvalue;
int probe ;
while tableindex && tableindex value && probe size
index index step size;
probe;
return probe size && tableindex value index : ;
@Override
public int hashint key, int probenumber
Double hashing using h and h functions
int result happlykey probenumber happlykey size;
return result result size : result;
@Override
public String toString
StringBuilder result new StringBuilder;
for int i ; i size; i
if tablei
int index i; Use the current index directly
if resultlength
result.append;
result.appendindexappendappendtablei;
return result.toString;
public static void mainString args
Function h key key ;
Function h key key ;
DoubleHashTable t new DoubleHashTable h h;
tinsert;
tinsert;
tinsert;
tinsert;
System.out.printlnttoString;
Expected output:
Current output is:
This is the interface:
public interface OpenAddressTable
@return the load factor of the table.
double loadFactor;
The dictionary insert operation.
@param value the value to be inserted into the dictionary.
@throws java.lang.NullPointerException if the value is null.
void insertint value;
The dictionary search operation.
@param value the value to search.
@return the index associated with the given value, or if the value is
not present in the dictionary.
int findint value;
The extended hash function, which takes a pair of values the key and the
probe number; where a probe number i indicates the ith slot
in the probe sequence.
@param key the key to be stored or searched in the hash table.
@param probenumber the number that specifies which element of the probe
sequence is to be calculated.
@return the slot number ie index or position to be probed in the table.
int hashint key, int probenumber;
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
