Takeaways
- A Map / Dictionary / HashTable is an unordered collection of Key-value pairs
- Keys should be unique, and should be an immutable data type (string, int, double)
- A hash function takes a key value, and maps to a "bucket" in O(1) time
- A hash table is just an array, where each spot in the array is a "bucket"
- A hash collision may occur if two keys map to the same bucket
- The key set/key space is the set of keys in a hash table
- Insertions and lookups happen in O(1) time (assuming key value is known and no hash collisions occur)
- The Hash table library in java is called HashMap
- HashMap documentation: https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
- A HashSet<> is a Set data type that uses a HashMap under the hood
- A set is a unordered collection of data with no duplicates
- HashSets have O(1) insertions, lookups, and removals
Code
February 11th code is a student database that utilizes a hash table to store information about students. The keys are the student ID numbers, and values are the Student objects.
February 13th code is the same student database program, but uses a HashMap and HashSet under the hood. PirateTranslator.java puts english-->pirate word mappings, and translate an english sentence to a pirate sentence.