Stage 2 · Lesson 4 of 6
Hash maps and sets
A stores pairs of keys and values, like a dictionary that links each word to its meaning. A turns each key into a position in an array, so looking up, adding and deleting take O(1) on average. A is the same idea with keys only.
Sometimes two keys land in the same position. This is a , and the map handles it by keeping a small list there (chaining) or trying another free slot (probing). The table also grows as it fills, so the average stays constant.
This is the most useful structure in the roadmap. When a problem asks "have I seen this before?", "how many times?" or "where is its partner?", a hash map usually turns an O(n²) search into O(n). To use a pair of values as the key, build a : a tuple or a combined string.
A question to check yourself, an AI practice session and 3 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Data Structures & Algorithms for Coding Interviews
Design Gurus · Beginner · Subscription
Each structure from first principles, with solutions in Python, Java, C++ and JavaScript
- CourseFreeAlgorithms, Part I
Princeton University · Intermediate
Free: the Stacks and Queues and Hash Tables modules, with the deque programming assignment
Practise
Keep handy
Also worth your time
How to pick a structure from the operations a problem needs