You want to update the value associated with a key in a hashmap. What is the general process involved?
Search for the key sequentially, and update the value when found.
Delete the existing key-value pair, then insert a new one with the updated value.
Calculate the hash of the key, find the corresponding bucket, and directly modify the value.
Hashmaps do not support value updates; you need to create a new 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 can lead to a high number of collisions for anagrams.
It can't handle strings of varying lengths.
It's computationally expensive.
It's not reversible, meaning you can't get the original string from the hash.
How are dictionaries typically implemented in programming languages?
Using linked lists for fast insertions.
Using binary trees for sorted key storage.
Using arrays for efficient indexing.
Using hashmaps to provide fast key-value lookups.
What is a disadvantage of using hashmaps when the number of elements to be stored is not known in advance?
They are more complex to implement than linked lists.
They might require resizing, which can be an expensive operation.
They are less memory-efficient than arrays for storing a fixed number of elements.
They are not suitable for storing data in a sorted order.
In hashmap terminology, what does 'collision' refer to?
When a hash function produces the same output for all inputs.
When two hashmaps have the same size.
When two keys map to the same index in the hashmap.
When trying to delete a key that doesn't exist.
Which of the following operations typically has a time complexity of O(n) in the worst case for a hashmap?
Deletion
Search
Insertion
All of the above
What is a significant disadvantage of using a hashmap when you need to retrieve elements in a sorted order?
Hashmaps have high memory consumption.
Hashmaps don't inherently maintain order.
Hashmaps cannot handle duplicate values.
Hashmaps have slow insertion times.
What is the time complexity of inserting a key-value pair into a hashmap in the average case?
O(n log n)
O(log n)
O(1)
O(n)
Why are hash functions typically designed to be fast to compute?
To minimize memory usage.
To maintain the sorted order of keys.
To prevent data loss during collisions.
To ensure efficient insertion, deletion, and search operations.
What is the time complexity, in the average case, for searching for a key in a well-implemented hashmap?