How does universal hashing enhance the robustness of hash tables?
By ensuring a uniform distribution of keys across the hash table
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
In the context of universal hashing, what makes a family of hash functions 'universal'?
Its ability to adapt to any data distribution
The guarantee of zero collisions for any input set
The property that the probability of collision between any two keys is bounded
Its use of a single, universally applicable hash function
In a system where memory usage is a major concern, what trade-off should be considered when using a hashmap?
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.
Collision resolution strategies have no impact on memory consumption.
Using a complex hash function always reduces collisions and memory usage.
In the worst-case scenario, what is the time complexity of searching for a key in a hashmap?
O(n)
O(log n)
O(1)
O(n log n)
Which collision resolution strategy is generally preferred for hash tables with open addressing when the load factor is low?
Quadratic Probing
Separate Chaining
Linear Probing
Double Hashing
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
Using a hash function that distributes keys evenly across the hash table
Storing keys with a wide range of values
Hashing two different keys to the same index in the hash table
You need to identify the first non-repeating character in a string. How can a hashmap be utilized to solve this problem efficiently?
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.
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.
A hashmap cannot be used efficiently for this problem.
When does rehashing typically occur in a hashmap?
Every time a new key is inserted.
When the load factor exceeds a predetermined threshold.
When the hash function is modified.
When the hashmap is cleared using the clear() method.
In the context of hashmaps, what does 'probing' refer to?
Determining the load factor of the hashmap.
Finding an alternative slot for a key when a collision occurs.
Resizing the underlying array to accommodate more keys.
Searching for a specific key in the hashmap.
You are implementing an LRU (Least Recently Used) cache. Which data structure, in conjunction with a hashmap, is most suitable for tracking the usage order of cached items?
Stack
Doubly Linked List
Binary Tree
Queue