Learning pathsA
Data structures

Binary search

Search a monotonic answer space.

Understand the problem

Write the predicate first. Keep an invariant for the search range and ensure every iteration strictly shrinks it. Boundary-search templates are safer than mixing inclusive and exclusive conventions.

Make it concrete

To find minimum ship capacity, ask whether capacity C can finish within D days. Feasibility stays true for larger C.

Trade-offs and pitfalls

The predicate cost multiplies the logarithmic number of search steps.

Check your understanding

Choose initial bounds for minimum shipping capacity.

Practice this topic

Your study notes