Data structures›Hash sets
Tutorial 5 of 13 · Data structures · Hashing · BeginnerHash sets
A collection that keeps each item once and tells you fast whether an item is there.
6 lessons, the last is a challenge · about 1 h · Python and Java
Before you startYou can write a few lines of Python or Java: variables, loops and functions
From the second lesson on, it helps to know hash maps: a key is turned into a slot number, and keys in the same slot form a chain
Watch first · about 6 minHash Sets: one question, answered at once. The narration uses an AI clone of the creator’s voice.What you’ll be able to do
- 1Say what a set is and why you would use one, and add to it and ask it questions in Python or Java.
- 2Explain why a hash set is a hash map with the values left out, and follow add, contains and remove through the table, collisions included.
- 3Work out union, intersection and difference by hand with membership tests, and say why the cost on average grows with n + m at most, not with n × m.
- 4Write the seen-set pattern to find repeats and remove them, and say why a set beats a list for this job.
- 5Use Python's set and frozenset and Java's HashSet, and know their costs, what they promise about order, and the rules for keys.
Lessons
Next in this path
Next: 6 · Two pointers and sliding window · 8 lessons · 1 h 39 min
Keep two positions in an array, move them by a rule, and avoid checking every pair.
Playground
Try the same model with your own values. No checks, nothing recorded.
Open the playground