Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you explain how Can you explain how STUDENT NAME (PRINT): Suppose that a has

ID: 3920294 • Letter: C

Question

Can you explain how
Can you explain how
STUDENT NAME (PRINT): Suppose that a hash table is implemented to use open addressing with instance variables as follows: public class OpenHashTable int size; int capacity; E seatsl: E ghost; // marks departed entries in the table // implementation omitted Hashing is performed as usual by using the method hashCode () of the class E Write an implementation for a method countSafeDrivers which returns the number of entries in the table whose insertion did not result in a collision.

Explanation / Answer

Since it is done in open addressing, if any collision have occured then the class will not be entered with its hashCode but will be entered with some probing done to it. SO if we try to match the objects hashcode with its serial number and it matches,collision didnt occured(the space was free) but if it dosnt matches then collision must have occured and probing must have done.

public int countSafeDrivers(){

int count = 0;

for(int i = 0;i<seats.length;i++){

E value = seats[i];

int hashCodeForValue = value.hashCode();

int entryForValue = hashCodeForValue%capacity;

if(i==entryForValue){

count++;

}

}

return count;

}

// I hope I was able to explain it thoroughly. If it is still unclear ask me in comments .All the best

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote