How are deletions typically handled in a hashmap with open addressing to avoid creating 'holes' that disrupt search operations?
By shifting all subsequent elements one position back to fill the gap.
By marking the slot as "deleted" and implementing a mechanism to handle such markers during search and insertion.
By simply removing the element, leaving the slot empty.
Deletions are not allowed in hashmaps with open addressing.
How does the choice of a hash function impact the performance of a hashmap?
A complex hash function guarantees a lower collision rate, improving performance.
A simple hash function is always preferred as it reduces computational overhead.
The hash function has a negligible impact on performance compared to the data structure itself.
A well-chosen hash function minimizes collisions, leading to faster lookups and insertions.
How does universal hashing enhance the robustness of hash tables?
By dynamically adjusting the hash function to the input data
By eliminating the possibility of hash collisions entirely
By minimizing the impact of hash collisions on retrieval time
By ensuring a uniform distribution of keys across the hash table
What is the purpose of dynamic resizing (rehashing) in a hashmap?
To reduce the number of keys stored in the hashmap.
To increase the size of the hash function's output range.
To improve the efficiency of key deletion operations.
To maintain a low load factor and prevent performance degradation.
You need to identify the first non-repeating character in a string. How can a hashmap be utilized to solve this problem efficiently?
Store the characters of the string as keys in the hashmap, and their positions as values. The first character with the lowest position value is the first non-repeating character.
Use the hashmap to store the unique characters of the string, then iterate through the hashmap to find the first non-repeating character.
Store the frequency of each character in the hashmap, then iterate through the string and return the first character with a frequency of 1.
A hashmap cannot be used efficiently for this problem.
In the worst-case scenario, what is the time complexity of searching for a key in a hashmap?
O(n log n)
O(n)
O(log n)
O(1)
Which of the following scenarios could potentially lead to collisions in a hashmap?
Having a hash table size much larger than the number of keys being stored
Storing keys with a wide range of values
Using a hash function that distributes keys evenly across the hash table
Hashing two different keys to the same index in the hash table
What is the primary advantage of using a hashmap over a simple array for storing and retrieving data?
Hashmaps use less memory than arrays.
Hashmaps can store duplicate keys, while arrays cannot.
Hashmaps maintain data in sorted order, unlike arrays.
Hashmaps provide faster access to data based on a key, while arrays require linear search in some cases.
In a hash table using open addressing with quadratic probing, if the initial hash function maps a key to index 'i', and a collision occurs, what is the index probed in the second attempt (assuming table size 'm')?
(i + 4) % m
(i * 2) % m
(i + 2) % m
(i + 1) % m
In a system where memory usage is a major concern, what trade-off should be considered when using a hashmap?
Using a complex hash function always reduces collisions and memory usage.
Collision resolution strategies have no impact on memory consumption.
Hashmaps always use less memory than arrays for storing the same data.
A larger hash table size generally results in faster lookups but consumes more memory.