SlideShare a Scribd company logo
Level up your coding skills with
the C++ Standard Template
Library (STL):
Algorithms: II
BY JOYJIT CHOUDHURY
Binary Search
 binary_search(), searches for an element equivalent to
val in the range [first, last)
 It returns true if any such element exists, else returns false
 The elements are compared using, either operator< (by
default) or comp (binary predicate)
 The elements in the range [first, last), shall already be
sorted according to this same criterion (either operator< or
comp)
Binary Search
 Time Complexity : O(logN), on containers which provide
random access iterators: vector, deque, array
 Time Complexity : O(N), on containers which provide non-
random access iterators: forward list, list
 Defined in the header <algorithm>
 Belongs to the namespace std
Algorithms: II
Algorithms: II
Lower Bound
 lower_bound(), returns an iterator pointing to the first
element in the range [first,last) which is not less than
(i.e. greater or equal to) the val
 If all the element in the range compare less than val,
the function returns last
 The elements are compared using, either operator< (by
default) or comp (binary predicate)
 The elements in the range [first, last), shall already be
sorted according to this same criterion (either operator< or
comp)
Lower Bound
 Time Complexity : O(logN), on containers which provide
random access iterators: vector, deque, array
 Time Complexity : O(N), on containers which provide non-
random access iterators: forward list, list
 Defined in the header <algorithm>
 Belongs to the namespace std
myV<int>
myV<int>
sort(myV.begin(),myV.end());
myV<int>
myV.begin() myV.end()
x
auto it = lower_bound(myV.begin(),myV.end(),25);
myV<int> x
it
myV<int>
myV.begin() myV.end()
x
auto it = lower_bound(myV.begin(),myV.end(),40);
myV<int> x
it
myV<int>
myV.begin() myV.end()
x
auto it = lower_bound(myV.begin(),myV.end(),100);
myV<int> x
it = myV.end()
Algorithms: II
Upper Bound
 upper_bound(), returns an iterator pointing to the first
element in the range [first,last) which is greater than
val
 If no element in the range compares greater than val,
the function returns last
 The elements are compared using, either operator< (by
default) or comp (binary predicate)
 The elements in the range [first, last), shall already be
sorted according to this same criterion (either operator< or
comp)
Upper Bound
 Time Complexity : O(logN), on containers which provide
random access iterators: vector, deque, array
 Time Complexity : O(N), on containers which provide non-
random access iterators: forward list, list
 Defined in the header <algorithm>
 Belongs to the namespace std
myV<int>
myV<int>
sort(myV.begin(),myV.end());
myV<int>
myV.begin() myV.end()
x
auto it = upper_bound(myV.begin(),myV.end(),7);
myV<int> x
it
myV<int>
myV.begin() myV.end()
x
auto it = upper_bound(myV.begin(),myV.end(),40);
myV<int> x
it
myV<int>
myV.begin() myV.end()
x
auto it = upper_bound(myV.begin(),myV.end(),100);
myV<int> x
it = myV.end()
Algorithms: II
 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!
Algorithms: II

More Related Content

What's hot (20)

PPTX
R: Apply Functions
DataminingTools Inc
 
PPTX
Data Structures - Lecture 3 [Arrays]
Muhammad Hammad Waseem
 
PPT
Arrays
archikabhatia
 
PPT
02 Arrays And Memory Mapping
Qundeel
 
PPTX
Arrays
Trupti Agrawal
 
PPT
Data Structure Midterm Lesson Arrays
Maulen Bale
 
PPTX
Arrays
Chirag vasava
 
PPT
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
PPT
Array Presentation
Deep Prajapati Microplacer
 
PPTX
stack & queue
manju rani
 
PDF
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
PPTX
Stack and Queue
Apurbo Datta
 
PPT
16858 memory management2
Aanand Singh
 
PPT
Arrays Data Structure
student
 
PPTX
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
PPT
List in java
nitin kumar
 
PPTX
Computer programming 2 Lesson 13
MLG College of Learning, Inc
 
R: Apply Functions
DataminingTools Inc
 
Data Structures - Lecture 3 [Arrays]
Muhammad Hammad Waseem
 
02 Arrays And Memory Mapping
Qundeel
 
Data Structure Midterm Lesson Arrays
Maulen Bale
 
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Array Presentation
Deep Prajapati Microplacer
 
stack & queue
manju rani
 
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Stack and Queue
Apurbo Datta
 
16858 memory management2
Aanand Singh
 
Arrays Data Structure
student
 
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
List in java
nitin kumar
 
Computer programming 2 Lesson 13
MLG College of Learning, Inc
 

Viewers also liked (15)

PDF
An Introduction to the C++ Standard Library
Joyjit Choudhury
 
PDF
SPOJ Problem: OLOLO
Joyjit Choudhury
 
PPSX
презентация 23 февраля 2017 г.
denchk
 
PPTX
Великий книжковий бум
biblioshelest
 
PPTX
1. initial plans(1)
Sydney Wratten
 
PDF
Mutualia- Gizarte Laguntzako Prestazioen Gida
mutualia
 
PDF
Mutualia- guia prestaciones de asistencia social
mutualia
 
PPTX
MRS Speaker Evening - Better Customer Communications with Behavioural Economics
Michelle Denslow
 
PPTX
Ammc's fabricated by friction stir process
Self-employed
 
PPT
презентація рубець і.я.
lanschool
 
PPTX
Care of client with hirschsprung’s disease
akhilesh pillai
 
PPTX
CIVIC TECH FORUM_20170325 Local Gov Tech
Masaki Takeda
 
PPTX
Förskolan flförskolan flerspråkighet som resurs 2
Malinspplugg
 
An Introduction to the C++ Standard Library
Joyjit Choudhury
 
SPOJ Problem: OLOLO
Joyjit Choudhury
 
презентация 23 февраля 2017 г.
denchk
 
Великий книжковий бум
biblioshelest
 
1. initial plans(1)
Sydney Wratten
 
Mutualia- Gizarte Laguntzako Prestazioen Gida
mutualia
 
Mutualia- guia prestaciones de asistencia social
mutualia
 
MRS Speaker Evening - Better Customer Communications with Behavioural Economics
Michelle Denslow
 
Ammc's fabricated by friction stir process
Self-employed
 
презентація рубець і.я.
lanschool
 
Care of client with hirschsprung’s disease
akhilesh pillai
 
CIVIC TECH FORUM_20170325 Local Gov Tech
Masaki Takeda
 
Förskolan flförskolan flerspråkighet som resurs 2
Malinspplugg
 
Ad

Similar to Algorithms: II (20)

PPT
Array
Malainine Zaid
 
ODP
Functions In Scala
Knoldus Inc.
 
PDF
Built in classes in java
Mahmoud Ali
 
PDF
Built-in Classes in JAVA
Mahmoud Ali Ibrahim
 
ODP
Day2
Karin Lagesen
 
PPT
Python Built-in Functions by A Technologies
AmitavaBiswas17
 
PPT
Vector3
Rajendran
 
PPT
Arrays
Komal Singh
 
PDF
Introduction to R programming
Alberto Labarga
 
PPTX
A brief introduction to apply functions
NIKET CHAURASIA
 
PDF
Introduction to R
University of Salerno
 
PDF
Statistics lab 1
University of Salerno
 
PPTX
Python programming workshop
BAINIDA
 
PPTX
Quality Python Homework Help
Python Homework Help
 
PDF
Matlab solved problems
Make Mannan
 
PPT
Java: Introduction to Arrays
Tareq Hasan
 
PDF
Matrices, Arrays and Vectors in MATLAB
Abu Raihan Ibna Ali
 
PDF
Data transformation-cheatsheet
Dieudonne Nahigombeye
 
PPTX
18. Java associative arrays
Intro C# Book
 
PPT
Introduction to matlab
BilawalBaloch1
 
Functions In Scala
Knoldus Inc.
 
Built in classes in java
Mahmoud Ali
 
Built-in Classes in JAVA
Mahmoud Ali Ibrahim
 
Python Built-in Functions by A Technologies
AmitavaBiswas17
 
Vector3
Rajendran
 
Arrays
Komal Singh
 
Introduction to R programming
Alberto Labarga
 
A brief introduction to apply functions
NIKET CHAURASIA
 
Introduction to R
University of Salerno
 
Statistics lab 1
University of Salerno
 
Python programming workshop
BAINIDA
 
Quality Python Homework Help
Python Homework Help
 
Matlab solved problems
Make Mannan
 
Java: Introduction to Arrays
Tareq Hasan
 
Matrices, Arrays and Vectors in MATLAB
Abu Raihan Ibna Ali
 
Data transformation-cheatsheet
Dieudonne Nahigombeye
 
18. Java associative arrays
Intro C# Book
 
Introduction to matlab
BilawalBaloch1
 
Ad

Recently uploaded (20)

PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Human Resources Information System (HRIS)
Amity University, Patna
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 

Algorithms: II

  • 1. Level up your coding skills with the C++ Standard Template Library (STL): Algorithms: II BY JOYJIT CHOUDHURY
  • 2. Binary Search  binary_search(), searches for an element equivalent to val in the range [first, last)  It returns true if any such element exists, else returns false  The elements are compared using, either operator< (by default) or comp (binary predicate)  The elements in the range [first, last), shall already be sorted according to this same criterion (either operator< or comp)
  • 3. Binary Search  Time Complexity : O(logN), on containers which provide random access iterators: vector, deque, array  Time Complexity : O(N), on containers which provide non- random access iterators: forward list, list  Defined in the header <algorithm>  Belongs to the namespace std
  • 6. Lower Bound  lower_bound(), returns an iterator pointing to the first element in the range [first,last) which is not less than (i.e. greater or equal to) the val  If all the element in the range compare less than val, the function returns last  The elements are compared using, either operator< (by default) or comp (binary predicate)  The elements in the range [first, last), shall already be sorted according to this same criterion (either operator< or comp)
  • 7. Lower Bound  Time Complexity : O(logN), on containers which provide random access iterators: vector, deque, array  Time Complexity : O(N), on containers which provide non- random access iterators: forward list, list  Defined in the header <algorithm>  Belongs to the namespace std
  • 9. myV<int> myV.begin() myV.end() x auto it = lower_bound(myV.begin(),myV.end(),25); myV<int> x it
  • 10. myV<int> myV.begin() myV.end() x auto it = lower_bound(myV.begin(),myV.end(),40); myV<int> x it
  • 11. myV<int> myV.begin() myV.end() x auto it = lower_bound(myV.begin(),myV.end(),100); myV<int> x it = myV.end()
  • 13. Upper Bound  upper_bound(), returns an iterator pointing to the first element in the range [first,last) which is greater than val  If no element in the range compares greater than val, the function returns last  The elements are compared using, either operator< (by default) or comp (binary predicate)  The elements in the range [first, last), shall already be sorted according to this same criterion (either operator< or comp)
  • 14. Upper Bound  Time Complexity : O(logN), on containers which provide random access iterators: vector, deque, array  Time Complexity : O(N), on containers which provide non- random access iterators: forward list, list  Defined in the header <algorithm>  Belongs to the namespace std
  • 16. myV<int> myV.begin() myV.end() x auto it = upper_bound(myV.begin(),myV.end(),7); myV<int> x it
  • 17. myV<int> myV.begin() myV.end() x auto it = upper_bound(myV.begin(),myV.end(),40); myV<int> x it
  • 18. myV<int> myV.begin() myV.end() x auto it = upper_bound(myV.begin(),myV.end(),100); myV<int> x it = myV.end()
  • 20.  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!