Map standard template library

In map the elements are stored in the form of pair?? Because we insert it in the form of pair is it different from the array base mapping in which I make array and for every index put a value in it??

hi @shampblocks, in map the values are stored as key-value pair , you can consider map as a generic extension of map as in array you can consider indexes as keys. but in map you can have your key as any data type as long as the value is unique . you will learn about how keys are mapped to values in hashing

In case of any doubt feel free to ask :slight_smile:
mark your doubt as resolved If you got the answer

So map use hashing data structure??

they use hashing concept for conversion of key to index , data structure used depends on whether you want ordering or not . stl map uses self balancing binary search tree as data structure , while stl unordered_map uses hash table as data structure

So when to use map and when to use unorder map?

when you want ordering (ordering means the order in which you inserted is same as the order in which data is stored i,e not randomly) then use map . when if there no use for ordering than go for unordered_map
time complexity for insertion , deletion and updation is o(logn) in map (compensation for ordering)
while for unordered_map it is O(1)

Ordering means key will be stored in sorted order??

If I put keys 3 6 1 then it became 1 3 6 ??

run this code : https://ide.codingblocks.com/s/216734

you will understand what i mean by ordering
If you have any doubt in this then do ask

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.