Question: JAVA QUESTION: Change the put function to choose as the starting point for linear probing, the location that 1/3 of the table size away from
JAVA QUESTION:
Change the put function to choose as the starting point for linear probing, the location that
1/3 of the table size away from the collision location (modulo the table size). That is: put
will still do linear probing, but the starting point will not be the next consecutive location.
public void put(K key, V val) { if (val == null) delete(key);
// double table size if 50% full commented out for experiments // if (N >= M/2) resize(2*M);
int i = hash(key); putCount++; // count the first probe if ( keys[i] == null) { keys[i] = key; vals[i] = val; N++; return; } //toDo experiment 3 // Modify the code to choose an alternate starting point for linear probing // as described in the instructions // collision occurred. Select a place to start probing int start = (i+1) % M; // normal linear probing starting place for (i = start; keys[i] != null; i = (i + 1) % M) { // linear probing putCount++; if (keys[i].equals(key)) { vals[i] = val; return; } }
keys[i] = key; vals[i] = val; N++; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
