Lower bound:
In binary search, the lower bound is the lowest position where the value could be inserted without breaking the ordering. In the C++ standard library, this bound will be represented by an iterator referencing the element before which the value could be inserted.
STL:
int lower = lower_bound(vec.begin(), vec.end(), target);
That function will return a int value, where we can put the target value with the compromising the sorted system.
Upper bound:
In binary search, the upper bound is the highest position where the value could be inserted without breaking the ordering. In the C++ standard library, this bound will be represented by an iterator referencing the element after which the value could be inserted.
STL:
int upper = upper_bound(vec.begin(), vec.end(), target);
That function will return a int value, where we can put the target value with the compromising the sorted system.
Comments
Post a Comment