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.

جو کم از کم جاننا ضروری ہے

اہم علامتیں

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

مختصر حل شدہ مثال

  • 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.

عام غلطیاں

اس قسم کے سوال کو کیسے پہچانیں

Next recommended lesson

Continue through this topic with Least You Need to Know: Big-O, Theta, and Omega.

Least You Need to Know: Big-O, Theta, and Omega

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

مشق شروع کریں