Data Structures19 sections · 729 units
Open in Course

Hash Set vs Hash Map

When to use which

Hash Set: stores unique elements. Use when you only care about presence.

  • "Have I seen this number?"
  • "Is this string in the dictionary?"

Hash Map: stores key-value pairs.

Use when you need to associate data with keys.

  • "How many times does each number appear?"
  • "What index did I first see this number at?"

In Python, set is a hash set, dict is a hash map. In C++, unordered_set and unordered_map.