Sets
A set stores unique elements with O(1) membership checks — it's a hash map where only keys exist. Use it whenever you want to answer "have I seen this before?" fast: deduplicating a list, tracking visited nodes in graph traversal, filtering a stream, counting unique visitors. Set operations (union, intersection, difference) are just nested membership checks. Ordered sets (tree-based, like C++ std::set or Java TreeSet) keep elements sorted for O(log n) ops — you give up constant-time lookup for the ability to iterate in order or find min/max. Probabilistic variants like Bloom filters trade accuracy for memory — a false-positive-acceptable "probably in set" check that uses a fraction of the memory of a real set. Used heavily in databases to skip disk reads for keys that definitely don't exist.