- Abstract data types: set, multiset (bag)
- Concrete data structures: hash table, circular buffer (circular queue, ring buffer)
- Set operations
- Implement
Setclass (backed by hash table) with the following set operations as instance methods and properties:__init__(elements=None)- initialize a new empty set structure, and add each element if a sequence is givensize- property that tracks the number of elements in constant timecontains(element)- return a boolean indicating whetherelementis in this setadd(element)- addelementto this set, if not present alreadyremove(element)- removeelementfrom this set, if present, or else raiseKeyErrorunion(other_set)- return a new set that is the union of this set andother_setintersection(other_set)- return a new set that is the intersection of this set andother_setdifference(other_set)- return a new set that is the difference of this set andother_setis_subset(other_set)- return a boolean indicating whetherother_setis a subset of this set
- Write unit tests to ensure the
Setclass is robust- Include test cases for each class instance method
- Annotate all instance methods with complexity analysis of running time and space (memory)
- Compare the behaviors of your
Setclass to those of the Pythonsettype
- Implement
CircularBufferclass (backed by dynamic array) with the following instance methods and properties:__init__(max_size)- initialize a new circular buffer that can store at mostmax_sizeitemssize- property that tracks the number of items in the bufferis_empty- check if the buffer is emptyis_full- check if the buffer is fullenqueue(item)- insertitemat the back of the bufferfront- return the item at the front of the bufferdequeue- remove and return the item at the front of the buffer
- Annotate
enqueueanddequeuemethods with running time complexity analysis - Write unit tests to ensure the
CircularBufferclass is robust- Include test cases for each class instance method and property
- Annotate
enqueueanddequeuemethods with running time complexity analysis