Question: Question 3: Change the put function to choose as the starting point for linear probing, the location that is as far away as possible from

Question 3: Change the put function to choose as the starting point for linear probing, the location that is as far away as possible from the collision location (i.e. half the table size away). That is: put will still do linear probing, but the starting point will not be the collision location.

// insert the key-value pair into the symbol table

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);

//toDo experiment 3

// Modify the code to choose an alternate starting point for linear probing

// as described in the instructions

int i;

for (i = hash(key); 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++;

}

See the Java file here with the full code: https://ufile.io/bhmtl

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!