Workspace Boundary Search
0d
Problem-solving patterns

Boundary Search

Find the first position that satisfies a monotone predicate.

Recognition signal

A first, last or insertion position matters even when keys repeat.

Method

Keep a half-open interval; on true retain the midpoint as a possible boundary.

Worked example

The lower bound for 3 in [1, 3, 3, 6] is index 1.

Common mistake

Finding any matching index may stop inside a run of duplicates.