Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

More Books

Students also viewed these Databases questions