In Python, what is the purpose of the __hash__ method when used in conjunction with dictionaries?
__hash__
To specify how a custom object should be converted into a hash value for use as a key.
To define a custom sorting order for keys in the dictionary.
To provide a mechanism for iterating over the key-value pairs in the dictionary.
To determine the maximum number of elements that can be stored in the dictionary before resizing.
In a hash table using double hashing, the second hash function is used to:
Generate a new key if a collision occurs.
Determine the step size for probing in case of a collision.
Determine the initial index to store the key.
Calculate the size of the hash table.
In a hash table with open addressing using linear probing, suppose we perform a sequence of insertions where each key hashes to the same index. What is the time complexity of the nth insertion in the worst case?
O(1)
O(n log n)
O(log n)
O(n)
In a web server implemented using a hashmap to store cached web pages, which collision resolution strategy is generally preferred for its performance in handling a high volume of concurrent requests?
Double Hashing
Separate Chaining with linked lists
Separate Chaining with balanced binary search trees
Open Addressing with linear probing
In the context of amortized analysis of hash table operations, what does the term "amortized" refer to?
The average time complexity of an operation over a sequence of operations.
The worst-case time complexity of an operation.
The best-case time complexity of an operation.
The time complexity of an operation when the hash table is full.
Why is it generally recommended to avoid using mutable objects as keys in hash tables?
Hash tables cannot store mutable objects as keys; only immutable objects are allowed.
Mutable keys make the implementation of the hash table significantly more complex.
Using mutable keys increases the memory overhead of the hash table.
Mutable keys can lead to inconsistent state if their values are modified after being inserted into the hash table.
Which collision resolution strategy generally performs better in terms of cache locality?
Both perform equally well
Open Addressing
Separate Chaining
Cache locality is irrelevant to hash tables
Which of the following statements accurately describes a key difference in the behavior of Python dictionaries and Java HashMaps?
Java HashMaps allow null keys and values, while Python dictionaries do not.
Java HashMaps are synchronized and thread-safe, whereas Python dictionaries are not.
Python dictionaries use separate chaining for collision resolution, while Java HashMaps employ open addressing.
Python dictionaries maintain insertion order, while Java HashMaps do not guarantee any specific order.
In the context of hashmaps, what is a 'universal hash function' primarily designed to protect against?
Data corruption caused by accidental hash collisions between legitimate inputs.
Collisions caused by malicious input specifically crafted to exploit a known hash function.
Denial-of-service attacks caused by hash flooding.
Attempts to guess the keys used in the hashmap by analyzing the distribution of hashed values.
How can a hash flooding attack impact the performance of a web server using a hashmap to store session data?
It has no impact on performance, as hash flooding attacks only target data integrity.
It can cause a denial-of-service by forcing the server to handle a large number of collisions.
It can lead to increased memory usage and faster response times.
It can improve the efficiency of the hashmap by distributing data more evenly.