Nerd For Tech
Published in

Nerd For Tech

What are Hash Tables, and How do we use them?


Idempotent — denoting an element of a set that is unchanged in value when multiplied or otherwise operated on by itself

If you’re familiar with JavaScript, you more than likely call hash tables Objects, in ruby, they are called hashes, and in python, they’re called dictionaries. Though how is this achieved? We can create objects such as the one below by using a hash function.

A hash function digests syntax, allocates memory with an associated address known as the key, and holds value.

When we want to set a key, like, a hash function will generate something that looks like this 18697449d7c48cf32cdd4f14857e68ee. There is no way to undo this or change it in any way. This process is known as idempotent, which accentually means that the same input will have the same output. You can test this yourself if you want. Go here and select the md5 hash generator and type in “name” for the string, and I guarantee that you’ll see this as the output 18697449d7c48cf32cdd4f14857e68ee. Hash generators are beneficial because, unlike arrays, we don’t need to iterate over anything to retrieve the value. We access the object we want using the associated key to that value, which will give us a high-speed output.

Hash tables can be handy when writing algorithms lets say we have to compare to arrays, and we want to check if any elements in an array exist inside another collection, for example.

We can minimize the number of operations in which the function will execute. The big-O of this would be O(n) because as the data increase, the number of operations to complete function execution will also increase. Without a hashMap, as I’m calling it, we’d have to create a nested for-loop that would increase the number of operations to O(n*2) or O(a*b) depending on the size of each input.

Hopefully, this helps clarify your understanding of what hash tables are and how we can use them. If you are struggling with data Structures and want to learn how you can get better at using them. I’d highly recommend that you check out Andrei Neagoie’s course on Mastering the coding interview. It’s an excellent resource, and It helped me a lot. He goes into deeper detail about most of the topics that I blog about and is one of my primary sources for education on data Structures.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cameron J. Leverett

Cameron J. Leverett


I love tackling new and exciting challenges and working with software because it’s consistently changing, which is exciting.