Math Fundamentals18 sections · 814 units
Open in Course

Lessons from Perfect Square

summary

Two lessons:

1.1. Binary search works on any monotonic function, not just sorted arrays. Here, x2x^2 increases as xx increases, so you can binary search over xx

2.2. When forbidden from using built-in functions, binary search often replaces them efficiently

This same pattern applies to cube roots, nth roots, and other inverse operations. If you can check a candidate answer quickly, binary search finds it in log time.