Questions tagged [lower-bound]

In mathematics, especially in order theory, a lower bound of a subset S of some partially ordered set (K, ≤) is an element of K which is less than or equal to every element of S.

A subset S of a partially ordered set K may fail to have any bounds or may have many different upper and lower bounds. By transitivity, any element less than or equal to any lower bound of S is again a lower bound of S. This leads to the consideration of greatest lower bounds (or infima).

181 questions
70
votes
10 answers

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

STL provides binary search functions std::lower_bound and std::upper_bound, but I tend not to use them because I've been unable to remember what they do, because their contracts seem completely mystifying to me. Just from looking at the names, I'd…
Don Hatch
  • 4,224
  • 3
  • 22
  • 41
43
votes
5 answers

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

Is there a function in that uses binary search, like lower_bound but that returns the last item less-than-or-equal-to according to a given predicate? lower_bound is defined to: Finds the position of the first element in an ordered range that has…
the_mandrill
  • 27,460
  • 4
  • 58
  • 90
28
votes
2 answers

What are the rules for the "Ω(n log n) barrier" for sorting algorithms?

I wrote a simple program that sorts in O(n). It is highly memory inefficient, but that's not the point. It uses the principle behind a HashMap for sorting: public class NLogNBreak { public static class LinkedListBack { public…
Ryan Amos
  • 5,164
  • 4
  • 31
  • 53
24
votes
8 answers

Implementation of C lower_bound

Based on the following definition found here Returns an iterator pointing to the first element in the sorted range [first,last) which does not compare less than value. The comparison is done using either operator< for the first version,…
Shamim Hafiz
  • 19,616
  • 36
  • 104
  • 164
18
votes
7 answers

Java equivalent of c++ equal_range (or lower_bound & upper_bound)

I have a List of object sorted and I want to find the first occurrence and the last occurrence of an object. In C++, I can easily use std::equal_range (or just one lower_bound and one upper_bound). For example: bool mygreater (int i,int j) { return…
Gob00st
  • 5,279
  • 6
  • 40
  • 69
17
votes
3 answers

Difference between basic binary search for upper bound and lower bound?

In the article http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=binarySearch, the author discusses binary search. He makes a distinction between finding the lowest value where something is true, and the highest value where something is…
John Targaryen
  • 897
  • 1
  • 11
  • 24
17
votes
4 answers

std::lower_bound and std::find on a plain array

I like to use std::algorithm whenever I can on plain arrays. Now I have 2 doubts; suppose I want to use std::lower_bound what happens if the value I provide as argument is not found? int a[] = {1,2,3,4,5,6}; int* f = std::lower_bound(a,a+6,20); The…
Abruzzo Forte e Gentile
  • 13,055
  • 24
  • 87
  • 163
16
votes
3 answers

Lower bound on heapsort?

It's well-known that the worst-case runtime for heapsort is Ω(n lg n), but I'm having trouble seeing why this is. In particular, the first step of heapsort (making a max-heap) takes time Θ(n). This is then followed by n heap deletions. I…
templatetypedef
  • 328,018
  • 92
  • 813
  • 992
12
votes
4 answers

Implementation of lower_bound on vector pairs

I know we need to include some compare function in order to achieve this. But not able to write for this one. For example: Elements of vector={(2,4),(4,2),(5,1),(5,3)} to find=5 lower_bound() should return 2 code-> #define pp pair bool…
user2826957
  • 303
  • 2
  • 3
  • 12
12
votes
8 answers

What .NET dictionary supports a "find nearest key" operation?

I'm converting some C++ code to C# and it calls std::map::lower_bound(k) to find an entry in the map whose key is equal to or greater than k. However, I don't see any way to do the same thing with .NET's SortedDictionary. I suspect I could implement…
Qwertie
  • 14,053
  • 15
  • 90
  • 131
11
votes
3 answers

The complexity of verifying solutions to NP-hard optimization problems?

There are many optimization problems that are known to be NP-hard, such as the traveling salesman problem, MAX-SAT, or finding the minimum chromatic number of a graph. Given a problem of this sort, I'm curious about the complexity of the following…
templatetypedef
  • 328,018
  • 92
  • 813
  • 992
10
votes
2 answers

The complexity of the multiplication of two lower triangular matrices

I know that the lower bound of the multiplication of two full matrices is Ω(n^2). Matrix multiplication I have been trying to prove that the lower bound of the multiplication of two lower triangular matrices using problem transformation method. My…
Alex Lin
  • 385
  • 2
  • 12
8
votes
1 answer

Test lower_bound's return value against the end iterator

In effective STL by Scott Meyers (page 195) there is the following line: "The result of lower_bound must be tested to see if it's pointing to the value you're looking for. Unlike find, you can't just test lower_bound's return value against the end…
dangerousdave
  • 5,926
  • 8
  • 39
  • 60
7
votes
4 answers

pubspec.yaml has no lower-bound SDK constraint

I was taking MDC101 flutter code lab. I cloned the starter project from the git repository as per the instructions but after clonning done, I executed flutter pub get and it gave me the following error. pubspec.yaml has no lower-bound SDK…
Feroz Khan
  • 687
  • 11
  • 20
7
votes
3 answers

Strange behavior of type inference in function with upper bound

Ran into this strange behavior when changed upper bound in the implementation, but forgot to change it in the interface. I think last statement should not compile, but it does and returns unexpected result. trait SuperBase trait Base extends…
Sergey Passichenko
  • 6,762
  • 1
  • 26
  • 29
1
2 3
12 13