Question: Python: Implementing a hash table that uses double hashing Your hash table class will be called HashTable. You will need to modify the put() and

Python: Implementing a hash table that uses double hashing

Your hash table class will be called HashTable. You will need to modify the put() and delete() functions discussed in class. You will also need to implement a number of your own functions. This should be done in steps as listed below:

Programme: Python

Python: Implementing a hash table that uses double hashing Your hash table

com Hashiable import HashTabl: In Lectures 26 and 27 e discussed the mplementatien of &hash table bat used linear probing for collision resolution In this esercise you will modity this hash table class so that it uses double hating for colisio, resolution. The hash table will also increase its size whenever its lod icor0.75 or moe. 1 he lash table will contin key-dana pairs. You can assume that keys will be imeger values and data strings import. random aninal_1iat "rvark". "hall"cat "dog". "lphant.". "lrog pzint ("Tear 1 h table HahTabiet tor i in range l1enlaninil 11st): self, data" [None] +sell. 22 Your hash table class will be called Hashable. The constructor for this class has no parameter. Five instance variables will be initialized: def hashfunction!^^!r, rey, 12e) - zuen kay e size- the size of the hash table in the hach table alota - a python list with alze umber of elements print (h tabler"count:lenth tble a python lst wi number or ekmants. . deleted- string oonsistg of the null character " tor 1 1n range lien anins1-11st): You will need to modify the put1 and daleca) tanctioas discussed in class. Ycu wil also need to implement a number of yor oa functions. This sould be done in steps as listed belou position while self._lots (position -one: prine (a tabie, ountlenable) print I. Modify the pat (I and deletefunctions so that the variable cont is altered appropriated whenever kry-data, pair isadded t er delted from the hash table. Chane te Lan function so that it retums this count 2. Your hash table will use the remainder mechod as discussed in lectures: print(- key % size. For collision resolution you will need to implement a second hash function: size-(key %(size-1)+1). You will need to alter the impemenlation of the rehash(I function o u this scand hash fundtion You will oimplment function al eneulales the losd aor e lash able. Rmember thar the oad facso is caculared using the fom h: tor 1 in rangel len!aninil list ) 3 key random.randrange(1000) 4. To increase the size of the hash table you wan so find a prime number that det put (5e12,key,dara) print(h table, "count : ", len(n cable appeoximatcly doubles its curret siac. For example ifyour hach table hs siac of 7, you will be looking mcreasing the sze ohe b to 13. You will need to mp ement a function that finds the largest prime number in the range 1 - - hah_valr.haah utkey, ln(lf. ota t sel.alotshash_valual - ane r peint O selt hash table propriately and rehashes all eisting key-data pairs into the appropriate slots in the larger hash table. You will need to modify the patO unction to e this resizei function appropriaily next 10--2-1f.xeh2.3hina5h v 1ue, len(3e12. 10tj) next aloaif.rehash (next s1at, 1n lif. aloza han poidl a file far you to test your heh table class A2Q3 py. An esampleof selt.data[nexe_slot]-data selt._datalnex_lot]-data det delete (seltr key): loif.haan tunccion(es. lenelt. alats) ev in slotel.lotssicion] while ke in lot-None: position-elt.rehash lpasition, lenlselt._lata) t position-start_lot: return None reurn aelf.aalete key def aeienaai, key.daca det esiten elt, ker) eir, sel: de xepx dars pinto'. " repl:-2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!