We have a poorly-designed hash map in which all of the stored values are contained inside a single bucket (i.e., they are all contained within a single LinkedList). Explain why this is detrimental to the benefits of using a hash map.
Data structure is a process to organize the data in such a form so that the accessibility of data becomes efficient or faster. Data structures provides the most efficient methods for data organization.
There are various types of data structure like array, linkedlist, tree, graph etc.
LinkedList is a linear data structure which stores the data in the form of nodes. Nodes contains the data and the reference to the next node. It overcomes the shortcomings of array for the static size.
HashMap is comprises of two words Hash and Map.
We know that Hashing is a technique in which the object is converted into integer value. It is used for faster searching, sorting or accessing the value.
Map is a data structure which contains the data in the form of (Key, value) pair. For a single key there will be one value. This (key, value) pair is known as entry.
So when we mix both the concepts, we get HashMap. HashMap is a data structures which stores the data entries in the buckets such that each bucket can have a series of entries in the form of linkedlist or array.
If we stores all the values in the same bucket then it weakens the hashmap structure. As we know that we are using single linkedlist for the entries and hence for accessing a any element in the bucket, we need to traverse from starting to that element as linkedlist needs to br traverse from the starting and hence it will increase the time complexity for that single bucket. Therefore, it will decrease the efficiency of the HashMap.