Invariants are often introduced as polished sentences: this quantity never decreases; this set contains exactly the processed vertices; this subtree stores the answer for its interval. The sentence is important, but fluency with the sentence is not yet control of the idea.

Control appears when a learner can inspect an operation and predict whether the invariant survives.

Begin with a fragile version

Take a synthetic graph search. Mark a vertex visited when it enters the queue, then ask what changes if marking is delayed until removal. On one small graph, two parents can enqueue the same vertex. The first duplicated entry is the moment the intended invariant fails.

The exercise has a precise target: name the invariant, locate the first violating operation, and show the smallest state that exposes it.

Make prediction come before execution

Give learners a sequence of operations and ask them to stop immediately before failure. Prediction prevents a debugger or final output from doing all the intellectual work. Afterward, execution can confirm or challenge the prediction.

Repair the operation, then restate the invariant

A repair should change both code and language. “Move this line” is weaker than “claim ownership when the vertex is enqueued, so every vertex has at most one pending entry.” The restatement connects the local edit to the global property.

Vary the surface

The same lesson pattern works for balanced data structures, greedy prefixes, dynamic-programming states, and loop invariants. Change the representation while preserving the reasoning task: predict, violate, minimize, repair, restate.

An assessment can then remove the familiar cues. Present a new operation and ask for either a proof that the invariant survives or a counterexample. That is closer to the decision learners will face outside the lesson.

An invariant states an obligation that every operation must preserve. Teaching the first point of failure turns that obligation from a slogan into a tool.