C++ | lower_bound() and upper_bound()

Revision en1, by organisedChaos, 2022-12-08 21:30:31

Brief overview:-

The functions upper_bound() and lower_bound() functions are useful when we have data stored in a non-decreasingly sorted format and in a given range in the data structure we want to find out:

  1. position of the smallest number just > (greater) a given number
  2. position of the smallest number >= (greater than or equal to) a given number

we can use these 2 functions.

upper_bound() :-

  • returns an iterator pointing to the element just greater than the given number

lower_bound() :-

  • returns an iterator pointing to the element greater than or equal to the given number
Tags c++, lower_bound, upper_bound, sorted

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English organisedChaos 2022-12-08 21:40:55 755
en1 English organisedChaos 2022-12-08 21:30:31 703 Initial revision (published)