|
| 1 | +## Class 7: Maps & Hash Tables |
| 2 | + |
| 3 | +### Topics |
| 4 | +- Abstract data types: [map (dictionary, associative array)][map] |
| 5 | +- Concrete data structures: [hash table] |
| 6 | +- [Hash functions], [collision resolution], [load factor], [dynamic resizing] |
| 7 | + |
| 8 | +### Resources |
| 9 | +- Review Make School's [hash table slides] |
| 10 | +- Watch Make School's [hash table video lecture] |
| 11 | +- Play with VisuAlgo's [interactive hash table visualization][visualgo hash table] |
| 12 | + |
| 13 | +### Challenges |
| 14 | +- Add new features to improve `HashTable` class using [hash table starter code]: |
| 15 | + - Add `size` property that tracks the number of hash table entries in constant time |
| 16 | + - Implement `load_factor` - return the [load factor], the ratio of number of entries to buckets |
| 17 | + - Implement `_resize` - perform [dynamic resizing] when `load_factor` exceeds `0.75` after an insertion (`set` is called with a new `key`) and rehash all key-value entries |
| 18 | + - Run `python hashtable.py` to test `HashTable` class instance methods on a small example |
| 19 | + - Run `pytest hashtable_test.py` to run the [hash table unit tests] and fix any failures |
| 20 | +- Annotate methods with complexity analysis of running time and space (memory) |
| 21 | + |
| 22 | +### Stretch Challenges |
| 23 | +- Implement an alternative hash table [collision resolution] strategy instead of [separate chaining] (popular variants include [linear probing], [quadratic probing], and [double hashing]) |
| 24 | +- Write additional test cases to expand the [hash table unit tests] to ensure your collision resolution strategy is robust |
| 25 | + |
| 26 | + |
| 27 | +[map]: https://en.wikipedia.org/wiki/Associative_array |
| 28 | +[hash table]: https://en.wikipedia.org/wiki/Hash_table |
| 29 | +[hash functions]: https://en.wikipedia.org/wiki/Hash_function |
| 30 | +[load factor]: https://en.wikipedia.org/wiki/Hash_table#Key_statistics |
| 31 | +[dynamic resizing]: https://en.wikipedia.org/wiki/Hash_table#Dynamic_resizing |
| 32 | +[collision resolution]: https://en.wikipedia.org/wiki/Hash_table#Collision_resolution |
| 33 | +[separate chaining]: https://en.wikipedia.org/wiki/Hash_table#Separate_chaining |
| 34 | +[linear probing]: https://en.wikipedia.org/wiki/Linear_probing |
| 35 | +[quadratic probing]: https://en.wikipedia.org/wiki/Quadratic_probing |
| 36 | +[double hashing]: https://en.wikipedia.org/wiki/Double_hashing |
| 37 | + |
| 38 | +[hash table slides]: slides/HashTables.pdf |
| 39 | +[hash table video lecture]: https://www.youtube.com/watch?v=nLWXJ6IDKmQ |
| 40 | +[visualgo hash table]: https://visualgo.net/hashtable |
| 41 | + |
| 42 | +[hash table starter code]: source/hashtable.py |
| 43 | +[hash table unit tests]: source/hashtable_test.py |
0 commit comments