Skip to content
Codeloom

Topics / Binary Search

🎯

Binary Search

The O(log n) workhorse — classic, lower/upper bound, and binary search on the answer.

Why learn Binary Search?

  • Once you trust the invariant, off-by-one bugs vanish.

  • Solves an enormous range of "find smallest x such that…" problems.

  • A core pattern interviewers test almost every loop.

What you can build with Binary Search

Classic search in sorted arrays Rotated array problems Binary search on the answer space

Binary Search tutorials

6 articles · page 1 of 1

Hand-written tutorials, ordered as a recommended learning path.

  1. 01 Binary Search Master binary search patterns for LeetCode including search space reduction, boundary finding, rotated array search, and practical templates.
  2. 02 Ship Packages Solve Capacity to Ship Packages Within D Days by binary searching the ship capacity. Includes feasibility check, tight bounds, and a worked example.
  3. 03 Find Peak Element Solve Find Peak Element in O(log n) by binary searching on the slope direction. Includes diagram and edge cases.
  4. 04 First Bad Version Solve First Bad Version with binary search and overflow-safe midpoint calculation. Includes API constraints and complexity.
  5. 05 Koko Bananas Solve Koko Eating Bananas by binary searching the eating speed. Includes the monotonic predicate, ceiling division, and complexity.
  6. 06 Search 2D Matrix Solve Search a 2D Matrix by treating the sorted matrix as a flat sorted array and binary searching. Includes index arithmetic and complexity.