Hi, everyone.
So in this video, we are going to see this topic in maps in C++, so in C++ there are basically two
types of map.
So the name of first one is only map and the name of a second one is basically unordered map.
So both these two maps are basically implemented in still standard, no liability, so just like they
are implemented and still states, our president still argues that both are still so likewise maps.
And I don't need a map.
They both are present and still.
So as discussed in last radio, so this map is basically implemented using balanced besty.
So that's why all the major function, insert, delete, search, so all the functions will take a lot
of time, almost log off and time and this one on Redmap.
So this is implemented using hash table.
So we will learn how stable we will learn about how stable more throughout our lessons, but not in
this video.
We will also implement our own.
So if you will use hash table, so basically in order to map uses hash table, then all the functions,
insert, delete, search, all the functions will take big off runtime, almost constant.
OK, almost big oftentime almost constant time.
So the name of this map is basically unordered.
So that means this map is the order to map.
Why this map is already mapped, because it uses besty and if you will see the beast so best basically
ordered there is ordering to your elements.
I can see one case bigger than another, if you will, do the reversal of Vesty.
So the output will be sorted.
So we can see if you like a great map, you can rotate map.
You can edit this map in a manner because this is ordered.
OK, so in this video, let us see the inbuilt implementation, let's use the inbuilt on and order the
map.
OK, so in this video, let's see the inmate in order to map.
So all the functions that are present for in order to map that also present for MAP, all the functions
are similar, but the time complexities are different.
So the functions are not present in our roadmap.
They will run in big off one time and the functions that are present in order to map, they will run
and log oftentime time.
So in this video, let's use an order to map.
Let's use the inbuilt on road map.
OK, so let's start.
OK, so let's write the code, so first of all, on A and let's say the name of map is my map.
So is this correct?
No, this is not correct because this unrooted map is actually a template.
So basically, you have to give the type of key and you also have to give that type of value.
So my guess should be strength and my value should be in danger.
So key is basically string and my value is basically integer.
So if you are using an order map, let us also include I don't need a map, otherwise it will give us
compiler error.
And we are also using string.
So let us include string also.
OK, so let's first run our program so that if there is incompletion error.
So our program is working fine.
So there are no compulsion at a certain tax, I will call this correct.
So let's first see how can we insert elements?
So first, let's see how can we insert elements inside the map?
So basically, what do we want to insert?
So we want to insert two things.
We want to insert key and we want to insert value.
So basically this in order to map this and map it stores, this key will appear in form of paper.
It will store this key value in form of this.
So if you will remember, we have started about Berglas.
So what I will do, I will make upir first one key, the second one value, and I will push this paper
in order to map.
I'm repeating myself.
This Redmap.
So in order to map store, give loopier in the form of stalky values in form of beers.
So what I will do, I will make a beer.
So this is basically in built in world class beers and world class, actually.
So I will use the inbuilt class.
I will give Mickey, which will be strong.
I will give my value, which will be integer, and then I will push this beer inside the map.
Simple LNC.
So first of all, I have to make beer, so beer first one is string a string and the values integer
and let's say the name FCP so we can use constructor that is present inside this class.
So ABC cameraman, stinko main teacher, and then we can use the insert function, so my map.
Not insert.
And what I will do, I will insert BRP.
Simple, now let us run our program so that if there's anything that we can come to know.
So our program is working fine, so there is no one takes at it.
So this was the first way of inserting there is another way of inserting, just like Eddie.
So the second way of inserting is very similar to areas where we will use square records.
So my map.
Square scratchcards.
He is DCF, which is a string.
And the value is to.
So this is second way to insert, so I always use this way to insert, so this is much, much better
than first making up here and then using the insert function.
So this is like just like any.
So this is.
Like Eddie, so we are inserting the elements inside.
My map to this is key, which is a string, and this is value, which is integer.
OK, so let's run our program.
Our program is working fine.
So there is no this.
OK, so after inserting.
What we can do, let's see, how can we access elements, how can we find or access elements?
So we can access elements using this square, because just like in any case, we were will do.
I will write out.
My map of.
ABC, so give me the value.
Corresponding to Gey ABC, so there value will be one.
OK, I inserted one inside the map.
So let's see.
So the value is one.
So we can use the square brackets to access the values and we can also use square records to insert.
Give a little bit inside the map.
Now, there is one more function to access the elements using the ADD function.
So what I will do out?
My map not we can use add function, so give me the value present at ABC.
So, again, the output will be one in one.
So I'll put this one in when one is so first one is due to square records and the second one is using
add function.
So what is the difference between ad function and the square brackets?
So let us try to understand.
So if the key so if the key is present inside the map, then they both are working same, they're working
the same, no difference.
Now, let's try to print something which is not present inside the map.
So, Skout.
My map, let's use add function to give me the value present at GHC.
So if you will see carefully, we have not pushed into the map.
So basically, JJ does not exist inside the map, so let's have no problem.
Let's see what will happen.
So we'll see you just giving me at it out of range.
So that basically means the Gilinsky is not present inside the map, so this ad function is throwing
me at it when the key is not present inside the map.
So this is throwing exception when the key is not present inside the map.
OK, so let's come get out.
And now let us use the square because.
So my map.
Of JJ, so give me the value besant that give me the value corresponding to Kiguchi.
Now, what do you think, what will happen?
So basically, these square brackets.
So there are two possibilities.
First one, if the key is present, so if the key exist, it will return me to value.
Now, the second is if the key if this key does not exist inside the map, then what the square brackets
will do.
So it will push this key inside the map and the value the default value it will insert will be zero.
So what this square bracket will do.
So if the key does not exist inside the map, it will push the key value pair inside the map and by
default the value will be zero and it will return mesero.
It will return the value zero.
So let's see.
So this guy is not present inside the map, so this square brackets will insert the value, value will
be zero and it will return Mesero.
Let's see.
So it is returning with zero.
It is first pushing the key inside the map with the value zero, with the default value zero, and then
it is returning me the default value, which is zero.
Now, my question is how to check whether a given key is present or not.
OK, so how to check whether a given keys basically present inside the map or not?
So if you will use the ADD function, it will give us added, it will throw us exceptional at the given
keys not present.
So we cannot use that function, if you will use the square, because then it will push, it will insert
the key inside the map and it will be the default value which is zero.
So I cannot use this square because so what can I do.
So basically I have a special function count.
I will use the current function to check whether given keys present inside the map or not.
So let's see.
So I have to check.
The presence of a key.
And we cannot use add function or square records.
So how to check whether a given is present or not, so I have a function count, so I will do my map
not count and I will give key.
So, for example, I want to check whether the key is BESANT or not.
So what this current function will do.
So what this function will do, it will count how many times the key is present inside the map.
So this current function, it will count how many how many times the given key is present inside the
map.
So in MAP, a key will represent only one time because I told you the keys are unique, the keys are
unique.
So called function will return only to things zero or one.
So this count function can return only two things to zero and one zero means the key is not present.
One means the keys present simple.
So basically, if the count is good, then zero, basically, if the count is one, that means the given
keys present so you can write.
The keys present, so keys JJ, so JJ is present.
In the early part.
You can say not present.
Let's put a line here also.
So if you read the program, what will your output so add this line.
But this great record will do so, this will record will push.
So this condition will become true because the judges present and output will be judges present.
So let's see.
JJ is Besant.
So now let's see how we can update our quiz.
So updating is so just like in Inari.
Martellus we will square Becket's So my map of.
Let's say I want to update the value of GABSI, so what I will do, ABC is do so.
Initially the value of ABC was one.
Now I make its value to 20.
OK, so that's how we will update.
Now, let us see how to find the size of the map, how many give a loopier are present so.
Let's put here.
Scout says.
So I have a function, my Web site, so it will give me how many developers are inside the map, so
I'm printing the size here.
And let us also Prentice's after GHC.
So I'm printing, say, two times.
OK, so first one is here before this great beckert and the second one is here, so hopefully the size
will increase by one because the square brackets will push GHC.
So the size of stool, then JJ was pushed and then the size becomes three and JJ is president.
So now let's see, how can we it is how can we delete?
So it is an entry from the map.
So I have a function, Daughtry's, so what I will do.
My God, it is so dysfunctional will take as input, so I want to raise Kijiji.
I'm raising the kids and now letus.
Copy this one and let us also copy the site.
So what will happen?
The sites will decrease by one.
And the Kiguchi is not pleasant anymore.
OK, so Kijiji is not Besant and the size of the map will decrease by one because it is an element.
So now let's see.
So JJ was present.
Then I deleted the GSA, I read the Kijiji, so size becomes torso's decreased by one and Jayjay is
not present anymore.
So basically, we know how to insert elements, how to insert given loopier, and it is just like any
so we know basically how to access the elements using square records, just like at all using add function.
So we have a function, my stepdad says, with the help of which we can find out the size of the map.
So now we have a function count, so with the help of function called, we can check whether a given
keys present or not.
So this current function, it counts how many time a given key is present so it can only return to things
zero or one zero means not present one misprision.
And for updating for updating our values again, just like today, we will use the square records for
erasing an entry we can use, it is function and it will take as input.
Then again, faith function and then again, can't function, so for our data map, for a simple map,
all the functions are the same.
But there are time, complexities are different.
They will run in, log in time and hear all the functions are running in big off one time question time.
So in next video and next few lessons, what we will do, we will solve some problems with the help
of an order to map and build a map so that you can have a better understanding.
Thank you.