What is a key advantage of using a hashmap over a sorted array for searching?
Hashmaps offer faster search on average.
Hashmaps consume less memory.
Hashmaps maintain data in sorted order.
Hashmaps allow duplicate keys.
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 computationally expensive.
It can lead to a high number of collisions for anagrams.
It can't handle strings of varying lengths.
It's not reversible, meaning you can't get the original string from the hash.
In hashmap collision resolution, what does separate chaining involve?
Finding the next available empty slot in the hash table.
Storing colliding elements in a separate overflow area.
Creating linked lists at each index of the hash table to store colliding elements.
Using a secondary hash function to resolve collisions.
Which of these is a disadvantage of open addressing compared to separate chaining in hashmaps?
Increased memory usage due to linked lists.
Clustering of elements can lead to performance degradation.
Cannot handle a large number of collisions efficiently.
Requires more complex implementation compared to chaining.
Why are hash functions typically designed to be fast to compute?
To ensure efficient insertion, deletion, and search operations.
To maintain the sorted order of keys.
To minimize memory usage.
To prevent data loss during collisions.
What is a disadvantage of using a hashmap?
Keys must be immutable.
Cannot iterate over elements in a specific order.
Inability to handle collisions.
Slow search speed.
In a symbol table implementation using a hashmap, what do the keys usually represent?
Memory addresses of variables.
Data types of variables.
Names of variables or identifiers.
Values of variables.
What is the primary role of the modulo operator (%) in simple hash functions?
To handle collisions effectively.
To sort keys in ascending order based on their hash values.
To map the hash code to a valid index within the array's bounds.
To generate a unique hash code for each key.
What is the time complexity, in the average case, for searching for a key in a well-implemented hashmap?
O(1)
O(n)
O(n log n)
O(log n)
What is a real-world application of hashmaps?
Storing and retrieving data in databases.
Performing depth-first search in a graph.
Compressing files to reduce storage space.
Sorting a list of numbers in ascending order.