What is the primary reason for using a prime number as the size of a hash table in many implementations?
To ensure an even distribution of keys across the hash table, reducing collisions.
To increase the speed of hash function computation.
To minimize the memory usage of the hash table.
To make the implementation of the hash table simpler.
In the context of amortized analysis of hash table operations, what does the term "amortized" refer to?
The worst-case time complexity of an operation.
The time complexity of an operation when the hash table is full.
The average time complexity of an operation over a sequence of operations.
The best-case time complexity of an operation.
Which of the following statements accurately describes a key difference in the behavior of Python dictionaries and Java HashMaps?
Java HashMaps are synchronized and thread-safe, whereas Python dictionaries are not.
Java HashMaps allow null keys and values, while Python dictionaries do not.
Python dictionaries maintain insertion order, while Java HashMaps do not guarantee any specific order.
Python dictionaries use separate chaining for collision resolution, while Java HashMaps employ open addressing.
How does using a cryptographic hash function with a random salt improve the security of a hashmap storing user credentials?
It prevents unauthorized users from accessing the hashmap's keys.
It makes it significantly harder for attackers to perform rainbow table attacks.
It eliminates the possibility of hash collisions.
It encrypts the data stored in the hashmap, making it unreadable without the decryption key.
What is the primary advantage of using a universal hash function?
It eliminates the possibility of collisions entirely.
It ensures constant-time performance for all operations.
It makes the hash table resistant to attacks that exploit patterns in the hash function.
It provides better performance than any single, fixed hash function.
Which collision resolution strategy generally performs better in terms of cache locality?
Open Addressing
Separate Chaining
Both perform equally well
Cache locality is irrelevant to hash tables
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 provide a mechanism for iterating over the key-value pairs in the dictionary.
To define a custom sorting order for keys in the dictionary.
To determine the maximum number of elements that can be stored in the dictionary before resizing.
In a hashmap implementation using open addressing with linear probing, what is the worst-case time complexity for searching for a key if the hash table is nearly full?
O(n log n)
O(log n)
O(n)
O(1)
In cuckoo hashing, how many hash functions are typically used?
3
1
2
It depends on the size of the hash table.
Which of the following is NOT a valid mitigation strategy against hash flooding attacks?
Implementing a random salt value in the hash function to make collisions unpredictable.
Switching to a different data structure like a tree-based map that offers consistent performance.
Employing a bloom filter to quickly identify and discard potentially malicious input.
Using a fixed-size hashmap to limit the maximum number of collisions.