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

Write a Java program to compare the performance of different hash functions of t

ID: 3711953 • Letter: W

Question

Write a Java program to compare the performance of different hash functions of type H(k)=k mod p where 'k' is the key and 'p' is the size of hash table and is prime . You have to generate five different values of prime p randomly from the range 25 - 100 and 25 key values again randomly from the range 1 to 20,000. Plot one graph to show the number of collisions for all hash tables. Write a Java program to compare the performance of different hash functions of type H(k)=k mod p where 'k' is the key and 'p' is the size of hash table and is prime . You have to generate five different values of prime p randomly from the range 25 - 100 and 25 key values again randomly from the range 1 to 20,000. Plot one graph to show the number of collisions for all hash tables. Write a Java program to compare the performance of different hash functions of type H(k)=k mod p where 'k' is the key and 'p' is the size of hash table and is prime . You have to generate five different values of prime p randomly from the range 25 - 100 and 25 key values again randomly from the range 1 to 20,000. Plot one graph to show the number of collisions for all hash tables.

Explanation / Answer

def put(self,key,data): hashvalue = self.hashfunction(key,len(self.slots)) if self.slots[hashvalue] == None: self.slots[hashvalue] = key self.data[hashvalue] = data else: if self.slots[hashvalue] == key: self.data[hashvalue] = data #replace else: nextslot = self.rehash(hashvalue,len(self.slots)) while self.slots[nextslot] != None and self.slots[nextslot] != key: nextslot = self.rehash(nextslot,len(self.slots)) if self.slots[nextslot] == None: self.slots[nextslot]=key self.data[nextslot]=data else: self.data[nextslot] = data #replace def hashfunction(self,key,size): return key%size def rehash(self,oldhash,size): return (oldhash+1)%size

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