Skip to main content

One doc tagged with "search"

View all tags

Binary search — halving a sorted array

This chapter explains binary search from the invariant of halving the search range each round. It covers implementation pitfalls (midpoint calculation, boundary conditions, non-shrinking ranges), time and space complexity, why iteration and recursion differ in space, and the conditions under which it applies.