CPKit
v1.6.1

Upper Bound

SearchingEasy

Find the first index where element > target in a sorted collection.

Alt+Shift+U

Configuration Panel

First Element Greater Target Index Highlight

5
0
8
1
12
2
12
3
12
4
38
5
56
6
72
7

Time Complexity

O(log N) search operations

Space Complexity

O(1) auxiliary variables
Conceptual Overview

Upper Bound returns the index of the first element in a sorted range that compares strictly greater than the target value (i.e. element > target).

Algorithm Idea

Run binary search using bounds low = 0, high = N. If mid value > target, shift high = mid, otherwise shift low = mid + 1.

Stable Sorting

N/A

In-place Memory

N/A

Source: CP-Algorithms search & sorting reference