// map uses red black self balencing tree in backend and it always stored keys in sorted manner
13
+
intmain ()
14
+
{
15
+
map<int,string>m;
16
+
// map can store any kind of data types even set, vector ..
17
+
// all the keys of map will always be unique
18
+
// map stores keys & values in sorted order
19
+
// if we keep string then it will be stored in lexographical order
20
+
21
+
m[8]="Shivendra"; // insertion takes O(logn)
22
+
m[3]="abc"; // O(logm)
23
+
m[5]="cdc"; // when we wrote this even after there is no value it will take any value by it self
24
+
m.insert({1,"shiv"});
25
+
// when you want to directly access some specific value in map using m[key] or m.find(key), these are log(n) operations as log(n)time is taken by map to search this key.
26
+
m.erase(3); // O(log(n))
27
+
auto it = m.find(3); // O(long(n))
28
+
m.erase(it); // O(log(n)) // it will delete the key 3 and value
0 commit comments