What is the time complexity, in the average case, for searching for a key in a well-implemented hashmap?
O(1)
O(log n)
O(n)
O(n log n)
What is the purpose of a load factor in a hashmap?
To determine when to resize the hashmap.
To measure the efficiency of the hash function.
To store the maximum number of key-value pairs.
To count the number of collisions.
What happens when a hash function produces the same index for different keys?
The key-value pair is discarded.
The hash function is automatically updated.
The hashmap raises an error.
A collision occurs.
How are dictionaries typically implemented in programming languages?
Using binary trees for sorted key storage.
Using linked lists for fast insertions.
Using hashmaps to provide fast key-value lookups.
Using arrays for efficient indexing.
In hashmap terminology, what does 'collision' refer to?
When two hashmaps have the same size.
When trying to delete a key that doesn't exist.
When two keys map to the same index in the hashmap.
When a hash function produces the same output for all inputs.
You want to update the value associated with a key in a hashmap. What is the general process involved?
Hashmaps do not support value updates; you need to create a new hashmap.
Calculate the hash of the key, find the corresponding bucket, and directly modify the value.
Delete the existing key-value pair, then insert a new one with the updated value.
Search for the key sequentially, and update the value when found.
Which of the following is NOT a typical operation supported by hashmaps?
Delete
Search
Insert
Sort
Why is a good hash function important for hashmap performance?
To ensure that keys are evenly distributed across the hash table, reducing collisions.
To minimize the number of comparisons required to find an element.
To reduce the memory used by the hash table.
To allow for efficient resizing of the hash table.
In hashmap terminology, what does a 'bucket' typically refer to?
An individual element within the hashmap's array.
The range of possible hash values produced by the hash function.
A linked list or other data structure used to handle collisions.
The load factor of the hashmap.
A simple hash function for strings could involve summing the ASCII values of each character in the string. What is a potential drawback of this approach?
It's not reversible, meaning you can't get the original string from the hash.
It can lead to a high number of collisions for anagrams.
It's computationally expensive.
It can't handle strings of varying lengths.