Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C++
  • Standard Template Library
  • STL Vector
  • STL List
  • STL Set
  • STL Map
  • STL Stack
  • STL Queue
  • STL Priority Queue
  • STL Interview Questions
  • STL Cheatsheet
  • C++ Templates
  • C++ Functors
  • C++ Iterators
Open In App
Next Article:
How to Find the Minimum Element in a List in C++?
Next article icon

How to Find the Minimum Element in a Deque in C++?

Last Updated : 27 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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: 3

Finding the Minimum Element in a Deque in C++

To find the minimum element in a std::deque container, we can use the std::min_element() algorithm provided in STL that takes the iterator to the first and last of the range and returns the iterator to the minimum element in the range.

Syntax to Use std::min_element()

min_element (first, last);

Here,

  • first is the iterator pointing to the beginning of the range.
  • last is the iterator pointing to the end of the range.

C++ Program to Find the Minimum Element in a Deque

The below example demonstrates how we can find the minimum element in a deque in C++.

C++
// C++ Program to demonstrates how we can find the minimum // element in a deque #include <algorithm> #include <deque> #include <iostream>  using namespace std;  int main() {      // Creating a deque with some elements     deque<int> myDeque = { 10, 5, 8, 3, 12 };      // Finding the minimum element using min_element     // function     auto res = min_element(myDeque.begin(), myDeque.end());      // Checking if min_element found a valid minimum element     if (res != myDeque.end()) {         cout << "Minimum Element in the Deque: " << *res              << endl;     }     else {         cout << "Deque is empty." << endl;     }      return 0; } 

Output
Minimum Element in the Deque: 3  

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




Next Article
How to Find the Minimum Element in a List in C++?

G

gauravgandal
Improve
Article Tags :
  • C++ Programs
  • C++
  • STL
  • cpp-deque
  • CPP Examples
Practice Tags :
  • CPP
  • STL

Similar Reads

  • How to Find the Maximum Element in a Deque in C++?
    in C++, double-ended queues, also known as deques, are sequence containers with the feature of insertion and deletion on both ends. They are similar to vectors but are more efficient for the insertion and deletion of elements from both ends. In this article, we will learn how to find the maximum ele
    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 Sum of All Elements in a Deque in C++?
    In C++, double-ended queues are sequence containers similar to vectors but are more efficient in the case of insertion and deletion of elements at both ends. In this article, we will learn how to find the sum of all elements in a deque in C++. Example Input: myDeque ={1,2,3,4,5} Output: Sum of all d
    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++. Examples Input: v = {2, 4, 1, 5, 3}Output: 1Explanation: 1 is the smallest element in the vector Input: v = {12, 34, 5, 7}Output: 5Explanation: 5 is the smallest element in the vector. Following are the 6 different meth
    5 min read
  • How to Find Median of All Elements in a Deque in C++?
    In C++, the median of the deque is defined as the middle element when the size of the deque is odd and the average of the middle two elements when the size is even in the sorted deque. In this article, we will learn how to find the median of all elements in a deque in C++. Example: Input:Deque = {3,
    2 min read
  • How to Find Mode of All Elements in a Deque in C++?
    In C++, deque is a container provided by the STL library of C++ that allows insertion and deletion from both ends. The mode of a deque represents the element that appears most frequently in the container. In this article, we will learn how to find the mode of all elements in a deque in C++. Example:
    2 min read
  • How to Find the First Element in a Set in C++?
    In C++, a set is a container that stores unique elements following a specific order. In this article, we will learn how to find the first element in a set. Example: Input: mySet = {1, 2, 4, 3, 8, 4, 7, 8, 6, 4} Output: First Element = 1Find the First Element in a Set in C++To find the first element
    1 min read
  • How to Find the Size of a Deque in C++?
    In C++, deque also known as double-ended queues are containers that allow efficient insertion and deletion operations from both ends of the deque. In this article, we will learn how to find the size of a deque in C++. Example: Input: myDeque = {10, 20, 30, 40, 50} Output: Size of the Deque is: 5Find
    2 min read
  • How to Find the Minimum Key in a Map in C++?
    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 avai
    2 min read
  • How to Access the First Element of a Deque in C++?
    In C++, deques also called double-ended queues are sequence containers that can perform insertions and deletions on both ends. In this article, we will learn how to access the first element of a deque in C++. Example: Input: myDeque = {1,2,3,4,5} Output: Deque Elements: 1 2 3 4 5 First Element: 1Acc
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences