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 !
Maps

Maps

  • 1.
    Level up yourcoding skills with the C++ Standard Template Library (STL): Maps BY JOYJIT CHOUDHURY
  • 2.
    Unordered Map  unordered_mapis 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)
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
    Map  map isa 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)
  • 8.
    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
  • 13.
     That’s notall. 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 !