VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdmin_element-in-cpp/

⇱ std::min_element in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::min_element in C++

Last Updated : 13 Apr, 2026

The std::min_element() in C++ is an STL algorithm that is used to find the minimum element in a given range. This range can be array, vector, list or any other container. It is defined inside the <algorithm> header file. In this article, we will learn about the std::min_element() in C++.

Example: Below example demonstrates how to find the minimum element in a vector using min_element() method:


Output
1
1

std::min_element() Syntax

std::min_element(first, last, comp);

Parameters

  • first: Iterator to the first element of the range.
  • last: Iterator to the element just after the last element of the range.
  • comp: Binary function, functor or lambda expression that compares two elements in the range. By default, it is set as < operator.

Return Value

  • Returns an iterator to the smallest element in the range.
  • When the range is empty, it returns iterator to the last.

More Examples of std::min_element()

We can find the minimum element of the given range using std::min_element().

Example 1: Find Minimum Element in Array


Output
1

Time Complexity: O(n), where n is the number of elements in array.
Auxiliary Space: O(1)

Example 2: Finding Minimum Element in Deque with Multiple Minimums

When there are multiple minimum elements present in the range, std::min_element() returns the iterator to the first minimum element.


Output
Index: 1

Time Complexity: O(n), where n is the number of elements in deque.
Auxiliary Space: O(1)

Example 3: Find Minimum Element in Vector of User Defined Data Type

We have to use a custom comparator to determine how to compare user-defined data types based on any of their properties.


Output
Ashok 11

Time Complexity: O(n), where n is the number of elements in the vector.
Auxiliary Space: O(1)

Working of std::min_element()

std::min_element() implements a linear search algorithm to find the smallest element in the range. It compares each element of the range one by one using the iterator/pointer provided to it as arguments. This is the reason why it gives O(n) linear time complexity.

std::min_element() is not specialized for sorted containers such as std::set, std::map, etc., and still compares all the elements of these containers to find the minimum element.

Comment
Article Tags: