Index

Module 02 · DSAChoosing the attack

Why the loop is right

Sorting and Searching
Sorting and Searching · Open board

Is the board this lesson reads closely. Its binary search panel marks lo, mid and hi over the sorted list 1 to 15, and one line underneath warns about the off-by-one: “nail the invariant (is hi inclusive? is the answer in [lo,hi]?) or you loop forever / skip it.” This lesson is that one line, taken seriously.

Before you start. Sorting & Searching gave you binary search: on a sorted list, look at the middle, throw away the half that cannot hold what you want, repeat, so a million items takes about twenty looks. Recursion & Dynamic Programming gave you recursion: a function that calls itself on a smaller copy of the problem, stopped by a base case it can answer directly.

Continue reading with a plan

The first three lessons of every track are free. This lesson is included with a plan, which unlocks every lesson, board, video, lab and paper for one price.

View plans →Already a member? Sign in

Review DSA →

Saved in this browser, and to your account when you sign in.