Ceil the Floor
beginnerFinds both floor and ceil of a target in a single binary search pass over a sorted array.
PhaseUpper Bound
x5
Floor—
Ceil—
Round 1 — upper_bound (Floor)
lo
mid
hi
1
[0]2
[1]8
[2]10
[3]10
[4]12
[5]19
[6]mid / ceil candidate
floor candidate / result
too big / too small
search window
Round 1 — upper_bound: lo=0, hi=7. Find first index where arr[i] > x=5.
1 / 19