Modified Binary Search
Modified binary search: binary search on a condition instead of a value, on a rotated array, and over the possible answers to a problem.
Modified binary search halves a range of candidates by asking a yes-or-no question that is false up to some point and true after it, so it finds that point in O(log n) tests whether the candidates are the indices of an array or the possible answers to a problem. It matters because many problems that never mention sorting have such a question hiding in them, and spotting it turns a linear scan into a logarithmic one. The topic opens on the first index where a condition turns true, finds the first faulty build in four tests instead of eleven, and gives the first-true template in Python, Java and TypeScript. It searches an array that was rotated, finds the slowest pump rate that empties every tank in time, shows the loop that never ends when mid rounds the wrong way, and ends with an exercise on cutting ropes into equal pieces.
Contents
8 cardsnot started