Hello all and welcome you to this new module.
So in this module we are going to start with a new data structure which is called hash maps.
So now let's get started and understand what exactly hash maps are.
Now a hash map and they are also known as hash table is a data structure that stores key value pairs.
Okay.
So till now we have seen many data structures starting from the basic list or an array.
Then we learned about the linked list.
Then trees stack queues bsts.
Right.
In a very basic sense, the whole idea behind my hash map is that it will be storing two things, the
first one being key, the second one being value.
It allows for fast retrieval of values based on the key by using a process called hashing.
Now once I have the key and the value, what I would like to do is if I provide you with the key, you
have to make sure that you give me the corresponding value which I stored for that key.
Right now, that can of course be done in lots of ways, but the idea here is that we want to make sure
that it is fast, right?
We use a process called hashing.
And the reason for that is my keys can actually be anything.
Now moving forward in this module we are going to learn each and every thing how it will be implemented.
But I just want to make sure that I'm able to give a basic idea first that what exactly is the process
or things which we are going to learn, right?
So each key is actually transformed into a unique index okay.
Through this hash function.
So this transformation is something known as hashing which is then used to access the value okay.
And if everything is done pretty nicely in an optimized manner we can do the same in constant time.
So in a way you are able to or you will be able to search for something in a constant time.
Having learned about the time complexity, I'm pretty sure you understand how good approach this is,
right?
Great.
So let us move forward Then everyone let us move.
Move forward and try to see some real world example for hash maps.
So real world example.
The very first one is actually.
Plain old dictionaries, right?
In dictionary the word is a key and the value is the definition.
Now many of you might be thinking that dictionary is kind of being used in lots of data structures.
Well, yes, because dictionary is a perfect example of a product which has been optimized and worked
upon or created with knowledge of lots of data structures and their operations.
Right?
A dictionary could have just a word and their definition storing the key value.
It could have been a dictionary where it is giving the answer, but it is also sorted, which help us
to quickly find the word as well.
Right?
Great.
Second.
A very easy one.
Phone contacts.
In our phone, you give the name of the contact and you will get the phone number.
Right.
So phone contacts.
Third student ID system.
So what happens if you are a student or let's say if you are even working somewhere, you have an employee
ID, you have a student ID or something assigned to you.
You can even think of this by a passport number, which is of course valid globally, right?
So we have a passport number.
Just by entering that we are able to get all the information right.
So in that case the key is the passport number or any unique identification number.
And based on that we can get the overall value which again can be anything.
Now all these applications of course are very fast right.
We are able to get the information almost instantly and the reason is that in the back end they are
using hash maps.
Now let us see some practical examples.
The biggest advantage of hash maps.
Right?
I like this data structure a lot.
Okay.
The reason is that it is used a lot from day to day uses as well as in your development as well.
So if you are a web developer, if you are a software developer, you will be using this hash maps a
lot.
The concept of hash maps.
Okay.
So let us see the practical examples.
Now everyone.
Talking about practical example, let us see the very first one.
Practical examples.
The first one is actually DNS lookup.
So many of you might not be aware.
But what happens when we actually hit google.com in our browser?
Okay, so let me just take you to a browser everyone.
So let us say when I enter google.com okay.
So what exactly is happening.
What do you feel that what exactly is happening here.
Well, the process is that for this URL.
Okay.
For this particular web address that is google.com.
Our browser doesn't know that okay.
Where are the Google servers and anything.
No we don't know that a DNS lookup is performed.
DNS is domain Name system okay.
In which in the back end a hash map is there, which gives us the website URL.
Okay.
And from that key we are able to get to the IP address.
That is the value okay.
So let us find out if that is actually true.
So let's say w w w dot google.com I will show you this practically.
So it is finding all these things.
And see this is one Google LLC server right.
So let us see the IP address.
Let me copy this one minute here.
Let me copy this copy address and let me open it in front of you one minute.
Great.
See, I have hit this address.
Because of that, it is saying that it is not secure.
But if I continue to site, I have been taken to Google.
Right?
Your browser does it without telling you.
Okay.
So everything is happening in the back end, but these IP addresses are the ones which are finally hit.
Now you can imagine how many websites are there, right?
How many websites are there?
And all these websites, they have their IP address which can be hit.
So yeah, that is the overall advantage of hash maps.
Second NoSQL DBS.
Most of you must have heard about Redis MongoDB okay.
So there are databases which is used to store values and they are very fast in their overall execution
in that as well.
We store the value as a key value pair.
Right.
Everyone.
So the basic idea behind them is also in Hashmaps.
Third caching.
In web browser.
For every website or web browser, what it does, it tries to store some images, some information on
that thing which can be used again and again.
So when you refresh it, instead of downloading the same again, it just load that from the cache.
Okay.
Caching in general is also a very important concept in the world of software development.
In the world of programming in general, because it helps you to make sure that you can get the things
quickly by saving it.
Once you have retrieved it okay, great.
So let us see one more example.
Everyone.
Symbol table.
Okay.
Symbol table.
In compiler.
So the very basic compiler which we are using to write code.
When you say that hey print a your compiler in the back end is actually maintaining a hash table where
if you are saying A, it doesn't know what A is, much like DNS server, it knows that.
Okay, for this A, I have some address where I will get this value, and using that particular address
which is stored in a hash table or hash map, it is able to quickly get you to the results.
Now you can have tomorrow thousands of variables, thousands of customers.
Anything.
Your overall compiler, your overall ID knows the information because it is being stored being maintained.
Okay, so that's the overall benefit everyone.
So the use cases of hash maps.
Now you might be thinking that it is being used at so many places.
Well that is actually the case.
Hash maps or hash table get used a lot.
And that is the reason we have to make sure that we understand each and everything, every concept,
as well as their implementation on how the same thing happens.
Okay, so great everyone.
This is all for the introduction.
Now in the next video we will continue our discussion.