Explain Hashmap/set to a 10 year old!

Say I am a person very fond of maths, science and fiction and so I collect books on these topics. Over the years I have collected 100's of these books and I keep them all in a bag. Now when I wish to read a particular math book, I open the large bag and look for the book in my bag. Sometimes it takes me an hour to find the book.

My dad had a clever idea and bought me three bags, red green and blue in colors. He told me to keep all math books in the red bag, science books in green bag and fiction one's in the blue bag. This simple reorganization of books would save me immense effort in finding the book I wish to read.

Now coming to hashmaps, the buckets every tutorial talks about are these bags of different colors, the mathematical functions are there to assign a color to each of the object(books in this case) and the attempt is to design a function so that we end up having nearly equal number of objects of each type/color.

Some smart people further tried to improve the design of each bag/bucket so that finding an item inside a given bag also becomes super efficient.

All this made hashmap one the best places to store objects.

Comments (2)