Loading topic
linear_search function from the previous chapter and asks one question: how much work does that function do, and how does the answer change with the input?5 min readwhile loops, and try/finally (or the equivalent in your language). The sen6 min readwhile loops, and have already seen why binary search only works on sorted data. Here the focus is the iterative algorithm itself: how it narrows the search range, how to trace it by hand, and which edge cases a 5 min readlo/hi/mid loop. It also assumes you know Big-O notation and the O(n) analysis of linear search. Here we work out exactly how many steps binary search takes, show why that number grows as log n, and cover 6 min read< against <=, mid against mid + 1, len(a) against len(a) - 1. This chapter replaces trial and error with a precise rule. You state what the range [lo, hi] means, then check every line against tha5 min read[lo, hi] and the half-open range [lo, hi), and that you can read basic Java and Python. The chapter covers one line of the algorithm, the line th6 min read[lo, hi] convention. Binary search works by throwing away half of the range on each step. The remaining half is a smaller binary search problem,5 min read[1, 3, 3, 3, 7], a search for 3 can return index 1, 2, or 3, depending on where the midpoints happen to land. When the target 6 min readbisect module from earlier chapters. You should also be comfortable reading Big-O expressions such as O(n), O(log n), and O(n log n). The goal here is a decision: given a r6 min read