Foundations of Hash Maps and Sets Quiz

Test your knowledge of hash maps and sets, including concepts like frequency counting, deduplication, and constant-time lookups. This quiz is designed for those new to these core data structures.

  1. Basic Hash Map Concept

    Which characteristic is a primary advantage of using a hash map over a list for searching values?

    1. Uses less memory than an array
    2. Can store duplicate keys
    3. Constant-time lookups for keys
    4. Preserves order of elements
    5. Values are automatically sorted
  2. Hash Set Utility

    What is the main use of a hash set when processing a list of items that may contain duplicates?

    1. To keep items in order
    2. To store items as key-value pairs
    3. To multiply each element by two
    4. To append items repeatedly
    5. To remove duplicate items
  3. Fundamentals: Frequency Counting

    Given a list of words ['apple', 'banana', 'apple', 'orange'], how can a hash map be used?

    1. To count the frequency of each word
    2. To encrypt each word
    3. To reverse the list
    4. To sort the words alphabetically
    5. To replace all words with numbers
  4. Key-Value Pair Structure

    In a hash map, what does each entry consist of?

    1. An index and a length
    2. A node and a pointer
    3. A position and a reference
    4. A key and a value
    5. A value and a counter
  5. Hash Set Constraints

    What happens if you try to add the same element to a hash set more than once?

    1. The element will only appear once
    2. The set will sort the entries
    3. The last element will be removed
    4. The set will throw an error
    5. The element will appear three times
  6. Hash Map Lookups

    Why are hash maps commonly used for checking if an item exists in a collection?

    1. Because they store values sequentially
    2. Because they are the only collection with sorting
    3. Because lookups are fast and generally constant time
    4. Because they allow storing values with multiple identical keys
    5. Because they discard duplicate entries automatically
  7. Set Operations

    Given two sets A = {1, 2, 3} and B = {3, 4, 5}, which operation gives the set of unique elements from both?

    1. Set subtraction
    2. Set expansion
    3. Set product
    4. Set union
    5. Set difference
  8. Hash Map Uniqueness

    What will happen if you insert the same key into a hash map twice with different values?

    1. An error is thrown
    2. Both values are stored
    3. Both values are deleted
    4. The key is duplicated with both values
    5. The new value overwrites the old value
  9. Set Deduplication Example

    If you create a hash set from the list [5, 5, 6, 7], how many elements will the set contain?

    1. 4
    2. 3
    3. 1
    4. 5
    5. 2
  10. Hash Map Value Access

    How do you typically retrieve the value associated with a key in a hash map?

    1. By providing the key
    2. By searching every value
    3. By appending the key to the map
    4. By sorting keys first
    5. By iterating from the start