Skip to content

Commit c9ff242

Browse files
authored
Update SHORT_NOTES_on_STL.md
1 parent bb92284 commit c9ff242

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

SHORT_NOTES_on_STL.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,23 @@
22

33
## map and unordered_map
44
map is a very important STL used in competitive programming. Map is implemented using Red-Black Tree. Maps store values in the form of a combination of a key value and a mapped value.
5+
Declaration:
6+
map<int,int>mm ;
7+
unordered_map<int,int>mm ;
58

6-
### find()
9+
### mm.find(k)
10+
Returns an iterator of the specified key value if it's been found in the map or returns an iterator to mm.end() if element not found.
11+
12+
map<int,int>mm;
13+
mm[4]=9;
14+
mm[3]=2;
15+
16+
auto it=mm.find(4);
17+
18+
if(it==mm.end())
19+
cout << "element not found" << endl;
20+
else cout << it->first << " " << it->second << endl; // prints- 4 9
21+
22+
complexity:
23+
for map complexity is logarithmic.
24+
for unordered_map complexity is constant(average), linear(worst).

0 commit comments

Comments
 (0)