Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This problem is long the entire question with the skeleton and test case files can be viewed at ctxt DOT io / 2 / AADwxZSpFA
This problem is long the entire question with the skeleton and test case files can be viewed at ctxt DOT ioAADwxZSpFA
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.
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