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.
Basic Hash Map Concept
Which characteristic is a primary advantage of using a hash map over a list for searching values?
- Uses less memory than an array
- Can store duplicate keys
- Constant-time lookups for keys
- Preserves order of elements
- Values are automatically sorted
Hash Set Utility
What is the main use of a hash set when processing a list of items that may contain duplicates?
- To keep items in order
- To store items as key-value pairs
- To multiply each element by two
- To append items repeatedly
- To remove duplicate items
Fundamentals: Frequency Counting
Given a list of words ['apple', 'banana', 'apple', 'orange'], how can a hash map be used?
- To count the frequency of each word
- To encrypt each word
- To reverse the list
- To sort the words alphabetically
- To replace all words with numbers
Key-Value Pair Structure
In a hash map, what does each entry consist of?
- An index and a length
- A node and a pointer
- A position and a reference
- A key and a value
- A value and a counter
Hash Set Constraints
What happens if you try to add the same element to a hash set more than once?
- The element will only appear once
- The set will sort the entries
- The last element will be removed
- The set will throw an error
- The element will appear three times
Hash Map Lookups
Why are hash maps commonly used for checking if an item exists in a collection?
- Because they store values sequentially
- Because they are the only collection with sorting
- Because lookups are fast and generally constant time
- Because they allow storing values with multiple identical keys
- Because they discard duplicate entries automatically
Set Operations
Given two sets A = {1, 2, 3} and B = {3, 4, 5}, which operation gives the set of unique elements from both?
- Set subtraction
- Set expansion
- Set product
- Set union
- Set difference
Hash Map Uniqueness
What will happen if you insert the same key into a hash map twice with different values?
- An error is thrown
- Both values are stored
- Both values are deleted
- The key is duplicated with both values
- The new value overwrites the old value
Set Deduplication Example
If you create a hash set from the list [5, 5, 6, 7], how many elements will the set contain?
- 4
- 3
- 1
- 5
- 2
Hash Map Value Access
How do you typically retrieve the value associated with a key in a hash map?
- By providing the key
- By searching every value
- By appending the key to the map
- By sorting keys first
- By iterating from the start