Assignment 11

1 minute read

Due: by the end of the calendar day on Monday, April 24, 2023

Assignment Requirements

In class, we started on the implementation of a set ADT backed by a hash table with chained collision detection. The class we started is called ChainedHashSet. Put it in a file called chained_hash_set.py.

Finish this implementation so that it includes all of the methods in the ADT we defined.

  • Set() Create a new, empty set. It returns an empty set collection.
  • add(val) Add a new value to the set. If the value is already in the set, do nothing.
  • in Return True for a statement of the form val in set, if the given value is in the set, False otherwise.
  • remove(val) Remove the given value from the set.
  • len() Return the number of values stored in the set.

and make sure it works with string values as well as integers.

Automated Testing

codePost is set up with some automated tests like these:

string_set = ChainedHashSet()
string_set.add("Pikachu")
string_set.add("Mew Two")
string_set.add("Dr. Carlson")
string_set.add("Dr. Mario")
string_set.add("Shiek")
string_set.add("Captain Falcon")
string_set.add("Mr. Game and Watch")
string_set.add("Jiggly Puff")
string_set.add("Kirby")

print(string_set)

print("Dr. Mario" in string_set) #Should be True
print("Star Fox" in string_set) #Should be False

string_set.remove("Mew Two")

print(string_set)

print("there are",len(string_set),"items in the table")

where we’d expect to get results like

0:['Dr. Mario']
1:[]
2:['Dr. Carlson']
3:[]
4:['Shiek', 'Captain Falcon']
5:[]
6:['Pikachu', 'Mr. Game and Watch']
7:['Jiggly Puff']
8:['Mew Two']
9:['Kirby']

True
False
0:['Dr. Mario']
1:[]
2:['Dr. Carlson']
3:[]
4:['Shiek', 'Captain Falcon']
5:[]
6:['Pikachu', 'Mr. Game and Watch']
7:['Jiggly Puff']
8:[]
9:['Kirby']

there are 8 items in the table

though not necessarily hashing to those same spots.

What to turn in

Turn in the following

  • a chained_hash_set.py file with your code
  • in your chained_hash_set.py file, include a comment that shows a sample run - what happened when you tested your code
  • if you use an AI tool, fill out and submit the AI Assisted Learning Reflection via the link on the course Blackboard page.

Submit your code to Assignment 11: Chained Hash Set on codePost.

Grading

This is a 4-point assignment. See the rubric from the syllabus.