Understanding lower bound algorithm
The strategy from the earlier example could be used to create an algorithm. To explain this algorithm, we will take an array sorted in ascending order and try to find the lower bound for a target number.
Algorithm
The lower-bound algorithm finds the first position in a sorted array where a given target value can be inserted without violating the sorted order. In other words, it returns the index of the first element that is greater than or equal to the target value. The algorithm begins by initialising two indices that define the current search range in which the lower-bound may exist.
Liking the course? Check our discounted plans to continue learning.