Question: Hello, The code below is a method to add or put a new key value into a Java hash table. I need to add the

Hello,

The code below is a method to add or "put" a new key value into a Java hash table. I need to add the count variable into this method that will increment when a collision occurs. Can you please show me where to add the "count" variable in the "put" method in order to do so?

Thank you!

//Initialize count variables:

private int count;

// 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

if (N >= M/2) resize(2*M);

int i;

for (i = hash(key); keys[i] != null; i = (i + 1) % M) {

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

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!