Upload
joyjit-choudhury
View
65
Download
0
Embed Size (px)
Citation preview
Level up your coding skills with
the C++ Standard Template
Library (STL):
Maps
BY JOYJIT CHOUDHURY
Unordered Map
unordered_map is an associative container that contains key-value pairs with
unique keys. It allows fast retrieval of individual elements based on their keys.
Internally, the elements in the unordered_map are not sorted in any particular
order with respect to either their key or mapped values
Search, insertion, and removal have an average time complexity of O(1)
It is typically implemented as a hash table
Defined in the header <unordered_map>
Belongs to the namespace std
(remember : using namespace std)
Insert elements
Erase elements
Lookup an element
Access and Modify an element
Map
map is a sorted associative container that contains key-value pairs
with unique keys. Keys are sorted by using the comparison function compare
Search, insertion, and removal have an average time complexity of
O(logN)
It is typically implemented as a balanced binary search tree
Defined in the header <map>
Belongs to the namespace std
(remember : using namespace std)
Map Search, insertion, and removal of elements with respect to map can
be done in the same way as that for unordered_map using the
functions insert(), erase(), find() and operator[]
The difference being, the different time complexities of these
operations with respect to the different containers
O(1) : unordered_map vs. O(logN) : map
The elements in map are stored in a particular order and allow range
based iterations, whereas unordered_map stores the elements in a
random order
That’s not all. There are many other functions
and techniques that could come in handy.
Read about them on cplusplus.com or
cppreference.com or somewhere else. Just
google it !