Which statement correctly describes the difference between a hash map and a hash set?
Think about whether each structure associates values with keys or just stores keys.
A hash map stores pairs of keys and their associated values, allowing lookup by key. A hash set stores only unique keys without any associated values.
Which of the following is a common use case for a hash set?
Consider when you only need to know if something exists or not.
Hash sets are used to store unique items and quickly check if an item is already present, which helps avoid duplicates.
Given a hash map and a hash set both implemented with good hashing functions, which statement about their lookup performance is true?
Think about how hashing works for both structures.
Both hash maps and hash sets use hashing to achieve average constant time (O(1)) lookup for keys. The presence of values in hash maps does not affect the lookup time complexity.
Which statement best describes the memory usage difference between a hash map and a hash set storing the same number of keys?
Consider what extra data each structure holds besides keys.
Hash maps store key-value pairs, so they require memory for both keys and values. Hash sets store only keys, so they use less memory for the same number of keys.
You need to track unique user IDs that have logged into a system and also store the last login timestamp for each user. Which data structure is the best choice?
Think about how to associate each user ID with its timestamp efficiently.
A hash map allows storing each user ID as a key with its last login timestamp as the associated value, enabling quick lookup and update. A hash set cannot store associated values.