Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your code must be in a file called hash_table.py. Your hash table implementation must be in a class called HashTable. Starter code is attached to

Your code must be in a file called hash_table.py. Your hash table implementation must be in a class called HashTable. Starter code is attached to this assignment.

You must use a Python built-in list (which is an array) for the table. The table array should never change its length after it's initialized.

Each table slot should contain a linked list of Node objects. The Node class is provided in the starter code. If a slot is empty, its value should be None, representing an empty linked list. You must use only the Node class for your linked lists - you may not create a wrapper linked list class. You may not modify the Node class.

Your HashTable class should have these methods:

  • __init__(n, hash_func): The constructor should take the table size and a hash function as arguments. It should initialize the table as a Python built-in list with n empty slots.
    • The hash function will take two arguments - the key to be hashed and the table size - and will return the hashed value of the key.
  • get(key): Takes a key as an argument. It should return its associated value in the hash table, or None if it's not in the table.
  • insert(key, value): Takes a key and a value as arguments. It should call hash_func on the key to get its table slot, then insert the key and the value into the linked list at that slot.
    • If the key is already in the table, it should overwrite the value at the existing key. This means that your table shouldn't contain any duplicate keys.
    • You'll need to store the value and the key in the linked list. Otherwise, you won't know which value is associated with which key if a slot contains multiple nodes.
  • remove(key): Takes a key as an argument. It should remove the Node with that key and return its value. If the key isn't in the table, it should return None.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

7. Discuss the implications of a skill-based pay plan for training.

Answered: 1 week ago