Hello @Kate_Portalatin,
Thank you for your feedback on the provided hash map implementation. Upon reviewing the code and your concerns, it appears there’s been a misunderstanding regarding how the hash map and its buckets are initialized and function.
The intention behind the DesignHashMap
class is to create a hash map with a specified number of buckets (keySpace
) to manage key-value pairs. Each bucket is meant to handle collisions that occur when different keys hash to the same index.
However, after reading your reply, a critical point concerning the initialization of these buckets is found with Collections.nCopies(keySpace, new Bucket())
. This approach, mistakenly initializes the ArrayList
with references to the same Bucket
instance across all indices, not separate instances as required for correct hash map operation. This error would lead to incorrect behavior, but not in the way of creating redundant entire hash tables within each bucket.
We are consistently working on updating this lesson to provide a much better understanding of hash maps. Thank you for letting us know about your concerns. Please feel free to share further suggestions and feedback. We’d be happy to help.