Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

lower-bound

Implementation of C lower_bound

December 7, 2023 by Tarik

Here are the equivalent implementations of upper_bound and lower_bound. This algorithm is O(log(n)) in the worst case, unlike the accepted answer which gets to O(n) in the worst case. Note that here high index is set to n instead of n – 1. These functions can return an index which is one beyond the bounds … Read more

Categories c Tags algorithm, binary-search, c++, lower-bound Leave a comment

function for finding last item less-than-or-equal to, like lower_bound

November 19, 2023 by Tarik

In a sorted container, the last element that is less than or equivalent to x, is the element before the first element that is greater than x. Thus you can call std::upper_bound, and decrement the returned iterator once. (Before decrementing, you must of course check that it is not the begin iterator; if it is, … Read more

Categories c++ Tags binary-search, c++, lower-bound Leave a comment

function for finding last item less-than-or-equal to, like lower_bound

May 8, 2023 by Tarik

In a sorted container, the last element that is less than or equivalent to x, is the element before the first element that is greater than x. Thus you can call std::upper_bound, and decrement the returned iterator once. (Before decrementing, you must of course check that it is not the begin iterator; if it is, … Read more

Categories c++ Tags binary-search, c++, lower-bound Leave a comment

rationale for std::lower_bound and std::upper_bound?

February 8, 2023 by Tarik

If you have multiple elements in the range [first, last) whose value equals the value val you are searching for, then the range [l, u) where l = std::lower_bound(first, last, val) u = std::upper_bound(first, last, val) is precisely the range of elements equal to val within the range [first, last). So l and u are … Read more

Categories c++ Tags c++, lower-bound, stl, upperbound Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa