|
| 1 | +## Class 7: Sets & Circular Buffers |
| 2 | + |
| 3 | +### Topics |
| 4 | +- Abstract data types: [set], [multiset (bag)][multiset] |
| 5 | +- Concrete data structures: [hash table], [circular buffer (circular queue, ring buffer)][circular buffer] |
| 6 | +- [Set operations] |
| 7 | + |
| 8 | +### Challenges |
| 9 | +- Implement `Set` class (set with hash table) with the following [set operations] as instance methods and properties: |
| 10 | + - `__init__(elements=None)` - initialize a new empty set structure, and add each element if a sequence is given |
| 11 | + - `size` - property that tracks the number of elements in constant time |
| 12 | + - `contains(element)` - return a boolean indicating whether `element` is in this set |
| 13 | + - `add(element)` - add `element` to this set, if not present already |
| 14 | + - `remove(element)` - remove `element` from this set, if present, or else raise `KeyError` |
| 15 | + - `union(other_set)` - return a new set that is the union of this set and `other_set` |
| 16 | + - `intersection(other_set)` - return a new set that is the intersection of this set and `other_set` |
| 17 | + - `difference(other_set)` - return a new set that is the difference of this set and `other_set` |
| 18 | + - `is_subset(other_set)` - return a boolean indicating whether `other_set` is a subset of this set |
| 19 | +- Write unit tests for to ensure the `Set` class is robust |
| 20 | + - Include test cases for each class instance method |
| 21 | +- Annotate all instance methods with complexity analysis of running time and space (memory) |
| 22 | +- Compare the behaviors of your `Set` class to those of the [Python `set` type] |
| 23 | + |
| 24 | +### Stretch Challenges |
| 25 | +- Implement `CircularBuffer` class with dynamic array |
| 26 | +- Write unit tests for to ensure the `CircularBuffer` class is robust |
| 27 | + - Include test cases for each class instance method |
| 28 | +- Annotate `enqueue` and `dequeue` methods with running time complexity analysis |
| 29 | + |
| 30 | + |
| 31 | +[set]: https://en.wikipedia.org/wiki/Set_(abstract_data_type) |
| 32 | +[multiset]: https://en.wikipedia.org/wiki/Set_(abstract_data_type)#Multiset |
| 33 | +[set operations]: https://en.wikipedia.org/wiki/Set_(abstract_data_type)#Operations |
| 34 | +[hash table]: https://en.wikipedia.org/wiki/Hash_table |
| 35 | +[circular buffer]: https://en.wikipedia.org/wiki/Circular_buffer |
| 36 | +[Python `set` type]: https://docs.python.org/3/library/stdtypes.html#set |
0 commit comments