Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Define the ChainingHashTable class which uses separate chaining to handle collision resolution. The class should contain: a constructor which is passed one parameter - the
Define the ChainingHashTable class which uses separate chaining to handle collision resolution. The class should contain:
- a constructor which is passed one parameter - the table size. Two instance variables are needed: the size of the table and the list of keys the table contains. Note that since we are using separate chaining, each element of the HashTable will itself be a list to store all the keys allocated to that particular slot.
- The get_hash_value(self, key) method which, when passed a key, calculates the slot where this key is to be stored. The get_hash_value() uses the hash function - key % table_size
- The __str__(self) method which provides a string representation of the hash table (in list of lists format, e.g., [[], [], [], [], []].
Submit your entire ChainingHashTable class.
For example:
Test | Result |
---|---|
x = ChainingHashTable(2) print(x) print(x.get_hash_value(2)) print(x.get_hash_value(5)) | [[], []] 0 1 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started