Binary search
Finding something in sorted data by checking the middle and throwing away the half it cannot be in. Repeat until found.
Think of it likeLooking up a name in a phone book. You open the middle, see whether you have gone too far, and repeat on the correct half.
The idea takes one sentence. Getting it exactly right is famously fiddly — most programmers write it wrong on their first attempt, usually by mishandling the boundaries or looping forever when two items remain.
Be deliberate about three things: whether your high boundary is included or one past the end, whether the loop condition uses less-than or less-than-or-equal, and how the boundaries move after each comparison. Pick one convention and use it every time.
The genuinely powerful version is binary searching on the answer. If a question is “what is the smallest capacity that gets this job done in time”, and you can cheaply test whether any given capacity works, you can over the possible capacities without any sorted list existing at all. This turns up constantly and is worth practising specifically.
You already met it: the number-guessing game in week 2 was binary search with a human doing the halving.
What it costs. A million items takes about twenty steps. Requires the data to be sorted already.
Where you meet it in real softwareLookups in sorted indexes, git bisect finding which commit broke a build, tuning a capacity or rate limit.