Hash Maps / Sets (lookups, frequency counting) Quiz

Test your understanding of hash maps and sets with these easy questions covering how they work, their common uses like lookups and frequency counting, and key concepts such as uniqueness and performance. Perfect for building a solid foundation in hash-based data structures.

  1. Basic Characteristics

    Which property uniquely distinguishes a set from a list in typical programming languages?

    1. A set only stores unique elements
    2. A set sorts elements automatically
    3. A set allows duplicate entries
    4. A set stores elements in order
  2. Hash Map Key Usage

    What happens if you add a value to a hash map using a key that already exists?

    1. The new value is ignored
    2. Both values are stored for that key
    3. The new value replaces the old one for that key
    4. The hash map throws an error
  3. Set Membership Check

    How do you efficiently check if an element exists in a set, for example, is 7 present in the set {1, 3, 7, 10}?

    1. Iterate through the set
    2. Use fast hash-based lookup
    3. Convert it to a list
    4. Sort the set first
  4. Hash Function Role

    What is the main role of a hash function in a hash map?

    1. To compute an index where the value is stored
    2. To compress all values
    3. To sort the keys alphabetically
    4. To encrypt the keys
  5. Value Frequency Counting

    Which data structure is most commonly used to count how many times each word appears in a sentence?

    1. Hash map
    2. Stack
    3. List
    4. Tuple
  6. Duplicate Removal Using Sets

    If you convert the list [3, 7, 3, 2] into a set, what will the result be?

    1. A set containing only 3
    2. A set containing 2, 3, and 7
    3. A set with paired elements
    4. A set containing 3, 7, 3, and 2
  7. Hash Map Key Uniqueness

    When using a hash map, what must be true about each key?

    1. Each key must be a string
    2. Each key must be sorted
    3. Each key must be unique
    4. Each key must have the same value
  8. Common Operations

    Which operation is usually fastest with a set compared to a list, for example when checking if 10 is present?

    1. Membership check
    2. Sorting elements
    3. Counting elements
    4. Appending elements
  9. Hash Map Default Value

    What is returned when you try to access a key that doesn’t exist in a typical hash map?

    1. The first value in the map
    2. A null or none value
    3. All values in the map
    4. A random value
  10. Hash Collisions

    What is a hash collision in the context of a hash map?

    1. When keys are always unique
    2. When two keys produce the same hash value
    3. When the hash map is full
    4. When a hash function fails