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

This is a data struct question in hash table. Thanks for help! Explain, in words

ID: 3822783 • Letter: T

Question

This is a data struct question in hash table. Thanks for help!

Explain, in words, what is wrong with the following hashCode () method: public class Point 2D {Double x, y; ... public int hashCode () {return x.hashCode()^y.hashCode ();} Give an example of many points that all have the same hashCode (). Explain, in words, what is wrong with the following hashCode () method: public class Point2D {Double x, y; ... public int hashCode () {return x. hashCode () + y.hashCode ();}} Give an example of 2 points that have the same hashCode ().

Explanation / Answer

Answer 4)
In this hashcode method for each point it will return the same hashcode,
for example let say value of x=2 and y=4;
than hashcode of x will give:x.hashcode*y.hashcode
hashcode of y will give:x.hashcode*y.hashcode
So both hashcode will be same but as x and y are different variables they must have different hashcode.


Answer 5)
In this hashcode method for each point it will return the same hashcode,
for example let say value of x=2 and y=4;
than hashcode of x will give:x.hashcode+y.hashcode
hashcode of y will give:x.hashcode+y.hashcode
So both hashcode will be same but as x and y are different variables they must have different hashcode.

example of points:x=2,y=4 and x=4,y=2

Note:Please do ask in case of any doubt,thanks!!

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