← capítulo

Binary search on the answer

Binary-search the space of ANSWERS, not an array. Optimization → repeated yes/no decision.

The reframe

Watch it search the answer space

Split [7,2,5,10,8] into 2. Candidate limits 10..32; green = feasible, red = not. Converges on 18: [7,2,5]=14, [10,8]=18.

Log vs linear checks

Range ~2M: scan every candidate = 228,000 checks; binary search = 20. Doubling the range adds ONE check.

Requirements + traps

Takeaway

Binary search only needs a monotone predicate — a sorted array is just one case. "Optimize" often reduces to "decide, repeatedly." Next tier: advanced & probabilistic structures.