Concept
Most binary search bugs are at the edges: an empty array, a target smaller than everything, duplicates, and the choice between lo < hi and lo <= hi. Writing the invariant down makes them go away.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Boundary conditions doing its job.
def lower_bound(a, target):
"""First index whose value is >= target; len(a) if none."""
lo, hi = 0, len(a) # invariant: answer is in [lo, hi]
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < target:
lo = mid + 1
else:
hi = mid
return lo
lower_bound([1, 2, 2, 5], 2) # 1
lower_bound([1, 2, 2, 5], 6) # 4Mixing the two templates: a half-open range [lo, hi) with a lo <= hi loop, or a closed range with hi = mid. Pick one invariant and keep every line consistent with it.
Your roadmap puts these before Boundary conditions, unless you already know them.
Once a session shows you understand Boundary conditions, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.