DSA and problem solving

Stage 2 · Lesson 4 of 6

Hash maps and sets

Arrays, hashing, linked lists, stacks and queues

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

Practise

Keep handy

  • The Collections Framework section: ArrayList, LinkedList, HashMap and ArrayDeque

Also worth your time

Mark this stage as not done?