Data Structures: Hash tables

Data Structures: Hash tables

Introduction

In this article, I will explain what I learned about Hash Tables. It's important cause it is one of the most used data structures in the industry. And also some language has its build-in hash tables JavaScript has objects, Python has dictionaries or a module to be imported like in c++ and java. Well let's start digging:

So what is exactly a hash table?

-Simply it is a collection of key-value pairs where every key is unique to its value.

image.png

Hashing

in this pic, we can see three main things: the keys, hash function, buckets: -buckets are the hash table I showed you before.

-the keys are the reference to the data, we use it to look up for the data like the index in an array.

-hash function take the value given and return a hash code which will indicate where the value is stored.

image.png

What it the advantages of this data structure?

  • Extremely fast to search, insert, or delete an element.

! You would notice the speed efficiency more with a large set of data

! Hash tables are faster when the length of data is known in advance

Downside?

Yes, of course, there is a downside nothing is perfect. this data structure is swift, and that's good, but it's not always the case, sometimes it won't be as fast. and that's when the collision happens. !collision is when two keys are hashed in the same bucket or slot. Having so many values in one slot will slow down the performance of course. but luckily there is a lot of solutions, we also call the collision resolution.

image.png

That's it for the hash table I hope I explain fine :)