Core · Module 7 · Lesson 4 of 11
Associative Containers: map, set and unordered_map
Pick ordered versus hashed lookup for the catalogue, compare O(log n) tree cost against average O(1) hashing, and use map, set and unordered_map without surprises.
By the end you can
- Compare ordered tree and hash table guarantees for lookup and iteration
- Use map, set and unordered_map for catalogue id and title search
- Predict invalidation, hash cost and ordering effects on performance
Builds on string: Characters, Storage and Small-String Optimization.
01 · A question first
You need title lookup by id and by keyword, plus a duplicate check for ISBN codes. One container keeps everything sorted, another answers in constant time but scrambles order. Which one holds the catalogue index, what does each lookup really cost, and when does hashing lose?
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- Start with the problem
- How the idea works
- Why it is correct
- What it costs
- Pitfalls and variations
- How to choose the index for a query
- Where it is used
03 · Practice
Asked in interviews
Something wrong with this lesson? Report a problem