Question: class HashNode: DO NOT MODIFY the following attributes / functions Attributes key: str: The key of the hash node ( this is what is used
class HashNode:
DO NOT MODIFY the following attributesfunctions
Attributes
key: str: The key of the hash node this is what is used in hashing
value: T: Value being held in the node. Note that this may be any type, such as a str int, float, dict, or a more complex object
deleted: bool: Whether or not the node has been deleted
initself key: str value: T deleted: bool False None
Constructs a hash node
key: str: The key of the hash node
value: T: Value being held in the node
deleted: bool: Whether or not the node has been deleted. Defaults to false
Returns: None
Time Complexity: O
strself str and reprself str
Represents the Node as a string
Returns: str representation of node
Time Complexity: O
eqself other: HashNode bool
Compares to see if two hash nodes are equal
other: HashNode: The HashNode we are comparing against
Returns: boolstating whether they are equal
Time Complexity: O
class HashTable:
DO NOT MODIFY the following attributesfunctions
Attributes you may edit the values of attributes but do not remove them
capacity: int: Capacity of the hash table
size: int: Current number of nodes in the hash table
table: List: This is where the actual data for our hash table is stored
primeindex: int: Current index of the prime numbers we are using in hash
primes
This is a list of all the prime numbers, from until used for hash This is a class attribute so it is accessed by HashTable.primes, NOT self.primes
initself capacity: int None
Construct an empty hash table, with the capacity as specified in the input
capacity: int: Initial capacity of the hash table. Defaults to
Returns: None
Time Complexity: O
strself str and reprself str
Represents the HashTable as a string
Returns: str
Time Complexity: ON
eqself other: HashTable bool
Checks if two HashTables are equal
other: HashTable: the hashtable we are comparing against
Returns: boolstating whether or not they are equal
Time Complexity: ON
hashself key: str int
The first of the two hash functions used to turn a key into a bin number
Assume this is O timespace complexity
key: str: key we are hashing
Returns: int that is the bin number
Time Complexity: Oassume
hashself key: str int
The second of the two hash functions used to turn a key into a bin number. This hash function acts as the tie breaker.
Assume this is O timespace complexity
key: str: key we are hashing
Returns: int that is the bin number
Time Complexity: Oassume
IMPLEMENT the following functions
lenself int
If you see a function prefixed and suffixed with two underscores, that means it is a magic method and should not be called directly we will deduct points for using them directly For example, this function is called using the Python builtin len method and not len
Getter for the size of the number of elements in the HashTable
This function should be one line!
Time Complexity: O
Returns: int that is size of hash table
setitemself key: str value: T None
Sets the value with an associated key in the HashTable
This should be a short, ~ line function. The majority of the work should be done in the insert method!
Time Complexity: O
key: str: The key we are hashing.
value: T: The associated value we are storing.
Returns: None
getitemself key: str T
Looks up the value with an associated key in the HashTable
If the key does not exist in the table, raises a KeyError.
This should be a short, ~ line function majority of the work should be done in the get method!
Time Complexity: O
key: str: The key we are searching.
Returns: The value associated to the provided key.
delitemself key: str None
Deletes the value with an associated key in the HashTable
If the key does not exist in the table, it raises a KeyError
This should be a short, ~ line function majority of the work should be done in the get and delete methods!
Time Complexity: O
key: str: The key we are deleting the associated value of
Returns: None
containsself key: str bool
Determines if a node with the key denoted by the parameter exists in the table
This should be a short, ~ line function majority of the work should be done in the get method!
Time Complexity: O
key: str: The key we are checking to be a part of the hash table.
Returns: True if key is in the HashTable, False otherwise
hashself key: str inserting: bool False int
Given a key string, return an index in the hash table.
Should implement probing with double hashing.
If the key exists in the hash table, return the index of the existing HashNode.
If the key does not exist in the hash table ie HashNode is None at the key return the index of the next available empty position in the hash table.
Collision resolution should implement double hashing with hash as the initial hash and hash as the step
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
