A Java Lesson: Introducing Hashmaps Kate Kuehl • 03.31.2021 Hi, I’m Kate Kuehl! Data Structures / Algorithms Nerd ● Massively failed my first algorithms interview, swore I would get better and did! ● Proudest accomplishment: Teaching Dijkstra's Algorithm to 10 year olds Full-Stack Software Engineer ● Has worked everywhere from Fortune 500 companies to early-stage startups on both the front and backend 1. The Problem Agenda 2. How Hashmaps Work 3. Code Example 4. Real World Applications 5. Questions? Prerequisites Basic Java Syntax How to do things such as imports and print Primitive Data Structures Such as byte, short, int, long, float, double, boolean, and char Non-Primitive Data Structures Such as Strings, Classes, and Arrays 1. The Problem a. Lookups in arrays b. How can we do better? Lookups in arrays 651-447-8165 1-800-273-8255 Javis Kelly 313-515-8772 651-867-5309 Mercy Amir 678-999 - 8212 Dave * These are random numbers, do not call them randomly How can we do better? 2. How Hashmaps Work a. Fundamentals b. Hash functions c. How to deal with collisions? Aka Chaining d. Worst and best case scenarios e. A note on HashMaps vs HashTables in Java Fundamentals Image source: Tutorialpoint Hash functions ● Can be simple or complex ○ Simple examples: First letter of a name or first number ○ Complex: Encrypted values Chaining Image source: hackerearth.com Best vs Worse Case Image source: livehacking.com HashMaps vs HashTables in Java ● HashMaps are not synchronized and are not thread safe (topics for another time) ● HashMaps are okay with null keys and values, HashTables cannot have null values ● HashMap was created after HashTable and is generally more advanced and preferred if you’re not using threads (you’ll probably know if you’re using threads) 3. Code Example https://replit.com/@KateKuehl/has hmaps#Main.java 4. Real World Examples a. Online Phonebook b. Compliers (keywords) c. Any lookup where an exact match is necessary d. Coding interviews (all the freaking time) See also: 5. Questions? a. Concerns b. Complaints c. Compliments