Hash table explained like I’m 5
Photo by Janko Ferlic from Pexels
I felt compelled to attempt an improvement on the existing resources on this topic because It took me a lot of time and frustration to find a resource that I felt explained it to a satisfactory and digestible degree.
Motivation
A hash table is worth our time because it provides some alternatives to the humble array. In many cases, A hash table requires less time complexity than an array does.
In a typical scenario, adding a new item to a hash table is done in constant time relative to the data structure, but in polynomial time (or less) relative to the size of the key of the data. Considering the key of the data is usually short, we can comfortably call this constant time.
For those unfamiliar with Big O, I’ll provide a brief description right now since it is important for the motivation of this data structure.
Big O:
Constant time or Big O([some number]) is an operation that takes a constant amount of time irrespective of the size of the data.
For example, if we had a pickup truck that could hold 2721.55 kilograms (or 3 tons), it would always take a fixed amount of time to transport anything less than 3 tons to the barn, because the size of the thing we are…