Question: Consider the following method that implements getting a key / value pair from a chaining hashtable. There are two potential ways to check if an

Consider the following method that implements getting a key/value pair from a chaining hashtable. There are two potential ways to check if an entry in a list is the one being looked up - we could use equals() or hash(), both shown below. Why do we prefer using equals? (If needed, assume that no resizing ever occurs.)
public Value get(Key key){
for(Entry e : entries [hash(key)])
if (e.key, equals (key))//normal way
//if(hash(e.key)= hash(key))//alternative way
return e.value;
return null;
}.
private int hash(Key key) i
return (key, hashcode() & 0x7fffffff)%M;
 Consider the following method that implements getting a key/value pair from

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

In a chaining hashtable using equals instead of comparing hash codes is preferred for the following ... View full answer

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!