What is a Hash Map?
A
A collection of unique values only B
A data structure that stores key-value pairs C
A sorted list of elements D
A stack implemented with hashing
Analysis & Theory
Hash Maps store data as key-value pairs for efficient lookup.
What is the primary advantage of using a Hash Map?
A
Maintains sorted order B
Provides O(1) average-time access to values by key C
Consumes less memory than arrays D
Stores duplicate keys automatically
Analysis & Theory
Hash Maps provide fast O(1) access to values by key under typical conditions.
Which of the following methods retrieves a value by its key in a Hash Map?
A
find() B
lookup() C
get() D
search()
Analysis & Theory
get() is commonly used to retrieve a value by its key.
What happens when you insert a key that already exists in a Hash Map?
A
It throws an error B
It keeps both entries C
It overwrites the existing value D
It ignores the new value
Analysis & Theory
Inserting an existing key replaces the old value with the new one.
How does a Hash Map resolve collisions?
A
Using binary search B
Through chaining or open addressing C
By sorting the entries D
It cannot resolve collisions
Analysis & Theory
Collisions are resolved by chaining (linked lists) or open addressing (probing).
What is the load factor of a Hash Map?
A
The ratio of used buckets to total buckets B
The number of duplicate keys C
The size of the keys D
The time taken to compute hashes
Analysis & Theory
Load factor measures how full the Hash Map is.
Which operation removes a key-value pair from a Hash Map?
A
delete() B
remove() C
clear() D
discard()
Analysis & Theory
remove() deletes a key and its associated value.
What happens if you try to get() a key that does not exist?
A
It throws an error B
It returns a default value or null C
It adds the key automatically D
It returns the first key
Analysis & Theory
get() typically returns null or a default value when the key is absent.
Which of the following is NOT a valid use case for a Hash Map?
A
Implementing a cache B
Counting occurrences of items C
Maintaining sorted order D
Associating IDs with objects
Analysis & Theory
Hash Maps do not maintain sorted order; a TreeMap or similar structure is used instead.
What is rehashing in a Hash Map?
A
Sorting keys alphabetically B
Clearing all entries C
Resizing the underlying array and recomputing hashes D
Converting keys to integers
Analysis & Theory
Rehashing resizes the array and recomputes all hash codes to distribute keys evenly.