Question: HELP ME PLEASE!! If you could have some explanation would be much helpful thanks. In this exercise, you are required to calculate the number of
HELP ME PLEASE!! If you could have some explanation would be much helpful thanks.


In this exercise, you are required to calculate the number of probes of an insertion into hash table using linear probing. For example, if a hash table contains the following elements: [None, 36, None, 24, None, 12, None], then the number of probes for inserting the value of 2 is 1 as the value at index 2 is "None" (i.e. this slot is available). The number of probes for inserting the value of 3 is 2 as the value at index 3 is not None but the next one is None. Given the simpleHashTable class definition in the answer box below, extend the simpleHashTable class by the following steps: Add a private dictionary named self._probes to store the key and the number of probes of each insertion. Modify the put (self, key) method. The put() method should also calculate the number of probes based on the key value. Insert the key and number of probes into the dictionary defined above. Add a method named get_probes_dictionary (self) which returns the probes dictionary. Submit the entire class definition in the answer box below. Note: you can assume the inserted keys are all unique and that the hash table is not full. For example: Test Result hash_table = SimpleHashTable(11) [88, 32, 35, 25, None, None, None, None, None, None, 10] values = [10, 88, 35, 25, 32] 10 1 for value in values: 25 1 hash_table.put(value) 32 3 print(hash_table) 351 probes = hash_table.get_probes_dictionary() 88 1 for key in sorted(probes.keys(): print(key, probes [key] hash_table = SimpleHashTable() [None, None, 2, 3, 4, 11, 18] values = [2, 3, 4, 11, 18] 2 1 for value in values: 3 1 hash_table.put(value) 4 1 print(hash_table) 11 2 probes = hash_table.get_probes_dictionary(18 3 for key in sorted (probes.keys()): print(key, probes [key]) 1 class SimpleHashTable: 2 def _init__(self, size=7): 3 self._size = size 4 self._slots = [None] * size 5 6 def _str_(self): 7 return str(self._slots) 8 def get_hash_code(self, key): 9 return key % self.__size 10 def put (self, key): 11 index = self.get_hash_code(key) 12, if self._slots[index] == None: #empty 13 self._slots[index] = key 14, else: 15 new_index = self.get_new_hash_code_linear_probing(index) 16 while self._slots[new_index] != None: #look for an empty slot 17 new_index = self.get_new_hash_code_linear_probing (new_index) 18 self._slots[new_index]=key 19 def get_new_hash_code_linear_probing(self, index): 20 return ( index + 1 ) % self._size 21 Precheck Check
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
