All lessonsOpen Open Open Open Open
6. Searching
Binary search variants
0 of 5 activities0%
Reading 1
First true / last false
Lower bound: first index with a[i] >= t. Upper bound: first index with a[i] > t.
Search on answer: binary search the answer space when mid can be checked with a predicate (e.g., minimum capacity).
Predicate must be monotonic.
// lower_bound style
while(lo<hi){
int mid=lo+(hi-lo)/2;
if(a[mid]>=t) hi=mid;
else lo=mid+1;
}Check 2
Monotonic
Search-on-answer needs the feasibility check to be
Fill in 3
First ge
Try it 4
Lower bound
First >= 4.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Count < t
Read n, sorted ascending array, t. Print how many elements are strictly < t.
main.cpp
Loading editor…