Hashing & Hash Tables
Use dicts, sets and counters for constant-time lookups and explain how hashing, collisions and resizing make that possible.
4 objectives 6 steps about 125 min
Learn it step by step
Read the lessons in order, try the practice checks, then prove the skill with the knowledge check.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Implement a hash map with separate chaining and load-factor-based resizing that passes randomized tests against dict.
- Solve counting, deduplication, grouping and complement-lookup problems (such as two-sum and anagram groups) in O(n) with dict, set, Counter and defaultdict.
- Explain when hash operations degrade to O(n) and what makes a key hashable, including consistent __hash__ and __eq__ on custom classes.
- Trace insert, lookup and delete in an open-addressing table with linear probing, using tombstones so deletions do not break probe sequences, and explain how clustering ties performance to the load factor.
Lesson plan
6 steps, about 125 min · 5 of 5 lessons available so far
- From Keys to Buckets Concept · 20 min
- Collisions, Load Factor and Resizing Concept · 20 min
- Lab: Build a Chained Hash Map Lab · 30 min
- Counting, Grouping and Complement Lookups Worked example · 25 min
- Custom Keys and Adversarial Inputs Concept · 15 min
- Check: Hashing Problem Set Knowledge check · 8 questions
Practise it
Write a HashMap class (put, get, delete, len, iteration) with chaining and doubling, verify it against dict over 10,000 random operations, then solve group-anagrams and longest-consecutive-sequence with the standard library. Add an open-addressing variant with linear probing and tombstones, and show with a probe-length histogram how clustering grows as the load factor approaches 1.
Build it from scratch
Practice builds that exercise this skill by re-creating a real technology.
- Build your own Search EngineIntermediate · 8–16 h
- Build your own BlockchainIntermediate · 8–16 h
- Build your own RedisIntermediate · 15–30 h
- Build your own Hash TableIntro · 3–6 h
- Build your own Programming LanguageIntermediate · 20–40 h
- Build your own GitIntermediate · 10–20 h
References
Hard prerequisites
Unlocks
Nothing depends on this skill yet.
On these roadmaps
Progress and evidence for this skill are shared across all of them.