How to Find the Minimum Key in a Map in C++? Last Updated : 01 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, a map is an associative container that stores key-value pairs. In this article, we will learn how to find the minimum key in a map in C++. Example: Input: myMap= {{10,"apple"},{5,"banana"},{20,"cherry"}};Output:Minimum key: 5Find the Smallest Key in a Map in C++There is no direct method available in C++ to find the minimum key in a map. We have to iterate the map elements one by one and find the minimum key by comparing them. C++ Program to Find the Minimum Key in a MapThe below example demonstrates how we can find the smallest key in a given map in C++ STL. C++ // C++ program to illustrate how to find the minimum key in // a map #include <iostream> #include <map> using namespace std; int main() { // creating map map<int, string> myMap; // inserting key-value pairs in a map myMap[10] = "apple"; myMap[5] = "banana"; myMap[20] = "cherry"; // Finding the minimum key auto minKeyIterator = myMap.begin(); // handle the case when map is empty if (minKeyIterator != myMap.end()) { // print the minimum key cout << "Minimum key: " << minKeyIterator->first << endl; } else { cout << "Map is empty!" << endl; } return 0; } OutputMinimum key: 5 Time Complexity: O(N), where N is the number of elements in the map.Auxilliary Space: O(1) Comment More infoAdvertise with us Next Article How to Find the Size of a Map in C++? B bug8wdqo Follow Improve Article Tags : C++ Programs C++ STL cpp-map CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Find the Maximum Key in a Map in C++? In C++, the Standard Template Library (STL) provides a map container to store elements in a mapped fashion so each element has a key value and a mapped value. In this article, we will see how to find the maximum key in a map in C++. Example: Input : myMap : {{1, 10}, {2, 20}, {4, 12}, {3, 44}}Output 2 min read How to Find the Minimum Element in a List in C++? In C++, a list is a sequence container provided by the STL library that stores data in non-contiguous memory locations efficiently. In this article, we will learn how to find the minimum element in a list in C++. Example: Input: myList = {30, 10, 20, 50, 40};Output: The minimum element in the list i 2 min read How to Find the Size of a Map in C++? In C++ STL, maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values. In this article, we will learn how to find the size of a map in C++ STL. Example: Input: myMap = { {1, "Sravan"}, { 2 min read How to Find the Minimum Element in a Deque in C++? In C++, a deque (double-ended queue) container is a dynamic array that allows insertions and deletions at both ends. In this article, we will learn how to find the minimum element in a deque in C++. Example: Input: myDeque = {10, 5, 8, 3, 12}; Output: Minimum Element in the Deque: 3Finding the Minim 2 min read How to Find the Size of a Map in Bytes in C++? In C++, maps are associative containers that store a key value and a mapped value for each element and no two mapped values can have the same key values. In this article, we will explore how to find the size of the map in bytes in C++. Example Input: myMap = {{âappleâ, 1}, {âbananaâ, 2}, {âcherryâ, 2 min read How to Find Minimum Element in a Vector in C++? Given a vector of n elements, the task is to find the minimum element using C++.ExamplesInput: v = {2, 4, 1, 5, 3}Output: 1Explanation: 1 is the smallest element in the vectorInput: v = {12, 34, 5, 7}Output: 5Explanation: 5 is the smallest element in the vector.Following are the 6 different methods 4 min read Like