Practice Discrete Math

Algorithms / Answer Space Binary Search

Least You Need to Know: Binary Search on Answers and Monotone Predicates

Sometimes you do not binary-search an array index at all. Instead you binary-search an **answer space** such as a capacity, time limit, or threshold, using a feasibility check that flips from false to true exactly once.

The least you need to know

Key notation

P(x) feasibility predicate for candidate answer x
false...false true...true monotone transition needed for first-true search
search space candidate answer values, not positions in an array

Tiny worked example

  • Suppose you need the smallest network bandwidth that can serve all requests.
  • Define `P(b)` = 'bandwidth `b` is enough'.
  • If `P(mid)` is true, keep smaller candidates by moving the right boundary left.
  • If `P(mid)` is false, larger candidates are still needed, so move the left boundary right.

Common mistakes

How to recognize this kind of problem

Start practice