However even so in this video we're going to see this topic in world 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 the second one is basically an order to map so
both these two maps are basically implemented in SD in standard them liability.
So just like vector that implemented in SDL stakes out president and Fs SDL queues up visited SDL.
So likewise maps and an ordered a map.
They both are present in SDL so as discussed in last radio so this map is basically implemented using
balanced BSG so that's why all the major function insert delete search so all the functions will take
lo fi in time almost log off and time and this one on read a map.
So this is implemented using hash table so we will learn hash table we will learn about hash table mode
throughout our lessons but not in this radio.
We will also implement our own history well 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 one time almost constant time.
OK.
Almost.
Big offer in time almost constant.
So the name of this map is basically unordered.
So that means this map is that our data map via this map is ordered map because it uses BSD and if we
will see the BSD.
So BSD basically ordered there is ordering to your elements.
I can see one case bigger than an edit if you will do D and read.
I was in love BSD so the output will be sorted so we can say if you would like.
Great map you can I the map you can I read this map in the SA data miner because this is ordered Okay
so in this video let's see the invert implementation.
Let's use the inbuilt on an ordered the map.
Okay so in this radial let's see the inmate on order to map so all the functions that are present for
order the 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 road map they will drown in big off one time and the functions
that are present in order to map they will run and log off on time.
So in this we do let's use an outdated map.
Let's use the invoked on that map.
OK so let's start
OK so let's write the code.
So first of all on a map and let's say the name of map is my map.
So is this correct.
No this is not correct because this unaware the 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 key
should be a string and my value should be integer so my key is basically string and my value is basically
integer.
So if you're using an outdated map let us also include and I read a map.
Otherwise it will give us compilation error and we are also using string.
So let us include string also
Okay so let's first run our program so that if there is in compiling an error through our program is
working fine.
So there are no compulsion at a certain text phase I will call this correct.
So let us 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 road map it stores this give a loop here in form of beer it will
store this give a loop in form of beers.
So if you really remember we have started about beer glass so what I will do I will make a beer.
First one key.
The second one value and I will push this beer in and out of the map.
I am repeating myself.
This a map so in order to map store give a loop here in form of store key values in form of beers.
So what I will do I will make up here.
So this is basically inbuilt in world class beers and middle class actually.
So I will use the inbuilt glass.
I will give my key which will be string I will give my value which will mean digit and then I will push
this beer inside the map.
Simple.
Let's see so first of all I have to make beer so beer.
First one is string keys a string and the values integer.
And let's say the name B so we can use constructor that is present inside.
This being a class
so ABC common instinct domain teacher and then we can use the insert function.
So my map dart.
Insert
and what I will do I will insert BHP simple.
Now let us run our program so that if there's any syntax edit we can come do no so our program is working
fine so there is no syntax in 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 it is what do we do.
We will use squared backwards so my map square brackets G is the E F 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 in string and this is value which
is in danger.
Okay so later in our program our program is working fine so there is no errors.
Okay.
So after inserting what we can do let's see how can we access elements.
How can we find on excess elements
so we can access elements using this great backwards just like in 80.
Okay so what I will do I will write C out my map of ABC.
So give me the value corresponding to key ABC so their value will be 1.
Okay.
I inserted 1 inside the map so let's see
so the value is 1
so we can use the square brackets to access the values and we can also choose a squared because to insert
give a loop here inside the map.
Now there is one more function to access the elements using the add function.
So what I will do see out my map dart we can use at function.
So give me the value present at ABC.
So again the output will be when N1 celebrities one and when one is so first one is due to squared records
and the second one is using add function.
So what is the difference between add function and the square brackets.
So it does try to understand so if the key so if the key is present inside the map then they both are
working same they are working the same no difference.
Now let us try to print something which is not present inside the map so see out my map.
Let's use add function to give me the value present at GHG so if you will see carefully we have not
pushed JJ into the my map.
So basically JJ does not exist inside the map so let's end our program and let's see what will happen
so we'll see who does giving me the outer fringe so that basically means the given key is not present
inside the map.
So this added function is throwing me at it when the key is not present inside the map.
So this is going exception when the keys are not present inside the map okay so let's come and get out
and now let us use this grid backwards.
So my map of GJ so give me the value doesn't that give me the value corresponding to key GHC.
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 exists it will return me the value.
Now the second is if the key if this key does not exist inside the map then what.
This is great backwards 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 about good 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 me zero.
Okay it will return the value 0 so let's see so this key GHG is not present inside the map.
So this squared Beckett will insert the value value will be zero and it will return to zero.
Let's see
so it is returning with zero it is first pushing the key inside the map with the value zero over 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.
Okay 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 this exception to the given
keys are not present so we cannot use our function if we will use the square brackets then it will push
it will insert the key inside the map and it will identity the default value which is zero.
So I cannot use this square backwards.
So what can I do.
So basically I have a special function count.
I will use the current function to check whether a given key is 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.
Our Square Records so how to check whether a given keys 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 in GHG is peasant or not.
So what this current function will do.
So what this current 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 under two things.
0 or 1.
So this current function can return only 2 things to 0 and 1 0 means the key is not present one means
the key is present.
Simple.
So basically if the count is good then zero.
Basically if the count this one.
That means the given keys present so you can write the keys present so keys GJ so JJ is present
in the US part.
You can say at present
let's put in line here.
Also
so if you in the program what will our output so add this line but this great record will look so the
square brackets will push GSA so this condition will become true because the chase present and you're
an output will be JJ is present.
So let's see
JJ is present.
So now let's see how we can update our keys so updating keys.
So just like in every my dear use we will use a square backwards.
So my map of let's say I want to update the value of key ABC.
So what I will do ABC is do.
So initially the value of ABC was 1.
Now I make its value to 20.
Okay so that's how we will update.
Now let us see how to find the size of the map.
How many key value here are present.
So let's put size here
see out.
Size
so have a function.
My God size.
So it will give me how many give a loop here are presently inside the map so I am printing the size
here and let us also parentheses after JJ so I am printing sides two beams okay.
So first one is here before this is squared Beckett.
And the second one is here.
So hopefully this size will increase by 1 because the square brackets will push.
J.
So the size of those two then.
J was pushed and then the size becomes three and JJ is spending.
So now let's see how can we.
It is how can we delude
so it is ing an entry from the map.
So I have a function da.
So what I will do my map dart it is so this it is function will take key as input so I won't do it is
key GHC I am erasing the Kijiji and now let copy this one and let us also copy the size.
So what will happen the size will decrease by 1 and the key G A Change is not present anymore okay so
Kijiji is not present and the size of the map will decrease by 1 because I'm erasing an element so nullity
so JJ was present then I deleted the GHB I erase the key Kijiji so size becomes too so it's decreased
by 1 and JJ is not pleasant anymore.
So basically we know how to insert element how do insert give a loop here and it is just like any so
we know basically how to access the elements using squared records just like get it all using add function
so we have a function my map God size 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 count we can check whether a given key is present or not.
So this current function it counts how many time a given key is present so it can only return 2 things
0 or 1 0 means not present when means present and for looting for beating our values again just like
today we will use this grid backwards for it using an entry we can use it is function and it will take
key as input then again same function and then again common function.
So for order to map for simple map all the functions are same but their time complexities are different
they will run in log in time and hit all the functions are running in big off one time question time.
So in next video in next few lessons what do we 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.